Skip to content

A project to reproduce steps for basic linux server setup and serving static site on GCP

Notifications You must be signed in to change notification settings

architxkumar/static-site-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Static Site Server

These are the documented steps I followed while working on the Static Site Server DevOps Project.

Steps

1. VM Creation

  1. Create new project on Google Cloud with your favourite name
  2. Press on Create VM on the project dashboard
  3. Enable the Compute Engine API
  4. On the machine configuation option, select E2 instance. Select Machine type to custom, enable shared cores and tone down the slider to 0.25.
  5. Under the OS and storage option, change to latest version of Ubtuntu
  6. For Data protection, select No backups
  7. For Networking, enable HTTP Traffic. It's cruicial as nginx will serve HTTP traffic.
  8. For security (optional), turn on secure boot.
  9. Click on create instance

2. Server Setup

  1. Generate SSH keypair on your local machine with the command
    ssh-keygen -t ed22519 -c "your_mail@example.com"

Note

Ensure the email is same as the one tied with Google Cloud account.

  1. Skip the passphrase on the prompt.
  2. Copy the contents of your public key (the one ending with .pub).
  3. Click on the Metadata card under Compute Engine's Settings section.
  4. Paste in the content under the SSH Keys header. This transfers the public key to all the created instances
  5. Restart your instance
  6. SSH to your instance by running the folllowing command
    ssh -i /path/to/private-key username@hostaddress

3. Nginx Installation & Setup

  1. Install the nginx by running the following command on Debian based system
    sudo apt update
    sudo apt install nginx
  2. Check if nginx service is running by running the following command
    sudo systemctl status nginx

Note

If it shows running, then you are good to go else you might have to enable nginx service manually

  1. Navigate to root directory to create a basic html webpage that is to be served

Note

This isn't the final html webpage that will be served

  1. Create a directory data/www on your root path.
  2. Create a file index.html and add a basic webpage of your choice

Tip

Feel free to explore HTML Boilerplate website.

  1. Edit the nginx.conf file to serve your index.html by referencing beginner's guide on nginx docs.
  2. Restart nginx by running the following the command
    nginx -s reload
  3. Visit the webpage by entering in the external IP Address of your VM.

Warning

If you are seeing the same setup page try deleting /etc/nginx/sites-enabled/ and restarting. Else, if you see a 403 forbidden webpage then it means that nginx found the webpage but doesn't have sufficient permission to read it. Look at this Neos article

3. Setting up rsync

  1. Ensure that local and remote machine have rsync installed
  2. Create your new webpage locally on your machine.
  3. In order to sync directory between local and host machine, run the following commands
     rsync -avz -e "ssh -i /path/to/private-key" /path/to/local/directory hostname@hostaddress:/path/on/remote/directory

Warning

Ensure the user on remote has permission to write file in the directory. Also be cautious of the trailing slash difference, it might have unwanted consequences.

  1. Restart nginx and enjoy!

About

A project to reproduce steps for basic linux server setup and serving static site on GCP

Topics

Resources

Stars

Watchers

Forks