These are the documented steps I followed while working on the Static Site Server DevOps Project.
- Create new project on Google Cloud with your favourite name
- Press on Create VM on the project dashboard
- Enable the Compute Engine API
- On the machine configuation option, select E2 instance. Select Machine type to custom, enable shared cores and tone down the slider to
0.25
. - Under the OS and storage option, change to latest version of Ubtuntu
- For Data protection, select
No backups
- For Networking, enable HTTP Traffic. It's cruicial as nginx will serve HTTP traffic.
- For security (optional), turn on secure boot.
- Click on create instance
- 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.
- Skip the passphrase on the prompt.
- Copy the contents of your public key (the one ending with
.pub
). - Click on the Metadata card under Compute Engine's Settings section.
- Paste in the content under the
SSH Keys
header. This transfers the public key to all the created instances - Restart your instance
- SSH to your instance by running the folllowing command
ssh -i /path/to/private-key username@hostaddress
- Install the nginx by running the following command on Debian based system
sudo apt update sudo apt install nginx
- 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
- 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
- Create a directory
data/www
on your root path. - Create a file
index.html
and add a basic webpage of your choice
Tip
Feel free to explore HTML Boilerplate website.
- Edit the nginx.conf file to serve your index.html by referencing beginner's guide on nginx docs.
- Restart nginx by running the following the command
nginx -s reload
- 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
- Ensure that local and remote machine have rsync installed
- Create your new webpage locally on your machine.
- 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.
- Restart nginx and enjoy!