Installing Nginx on a Google Cloud Platform (GCP) Virtual Machine

When diving into DevOps, understanding cloud infrastructure and server management is essential. This guide will walk you through the basics of virtualization, virtual machines, and cloud computing before demonstrating how to create a virtual machine (VM) on Google Cloud Platform (GCP) and install Nginx.
What is Virtualization?
Virtualization is the process of creating virtual replicas of physical computing resources like storage, operating systems, and networks. It allows hardware resources to be partitioned into multiple virtual computers, known as virtual machines (VMs). Learn more about virtualization here.
What is a Virtual Machine (VM)?
A virtual machine is a software-defined computer that exists within a physical server. It has its own CPU, memory, storage, and network capabilities. VMs can run on your local machine or on remote servers. Discover more about VMs and their benefits.
What is Cloud Computing?
Cloud Computing utilizes remote servers hosted on the internet to store, manage, and process data, instead of relying on local machines or servers. Google Cloud Platform (GCP) is one such cloud service. Learn more about cloud computing here.
Creating a Virtual Machine on GCP
Sign up for GCP: Create an account on the Google Cloud Platform.
Create a VM:
Select Create VM as show in the image

Enable Compute Engine API

Click the Create Instance button in the navigation bar.

Configure the VM:
Name: Change from instance-20250203-074548 to test.

Region: Leave as default.
Zone: Select us-central1-a.
Choose OS and Storage:
In the sidebar, select OS and Storage.
Select Change button

Change the operating system from Debian to Ubuntu.

Click Select to save changes.
Set Up Networking:
In the Networking section, check the boxes for:

Change the operating system from Debian to Ubuntu.

Click Select to save changes.
Create the VM: Click the Create button to start the VM instance.
Connect via SSH:
Open the SSH terminal in your browser.

Authorize the connection to your VM.
Installing Nginx on the VM
Update Packages:
sudo apt updateInstall Nginx:
sudo apt install nginx -yConfigure Firewall:
sudo ufw app list sudo ufw allow 'Nginx HTTP' sudo ufw allow 'Nginx HTTPS' sudo ufw allow 'OpenSSH' sudo ufw enable sudo ufw statuscheck Nginx Status:
sudo systemctl status nginxVerify Installation:
curl http://localhost curl http://your_external_ip_address
Customizing the Nginx Welcome Page
Edit the Default Web Page:
sudo vi /var/www/html/index.htmlInsert the Following HTML:
<!DOCTYPE html> <html> <head> <title>Welcome</title> </head> <body> <h1>Welcome</h1> <p>Welcome to DevOps Stage 0 - [Your Name]/[SlackName]</p> </body> </html>- Save and exit the editor (
:wq).
- Save and exit the editor (
Adjust Permissions:
sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/htmlRestart Nginx:
sudo systemctl restart nginxTest the changes:
curl http://localhost curl http://your_external_ip_address
Common Challenges
Issue: Unable to access the external IP via HTTP/HTTPS.
Cause: Forgot to check the HTTP and HTTPS boxes in the GCP Networking interface, even though the firewall rules were enabled on the server.
Solution: Ensure these options are selected during VM setup.
Need a DevOps Engineer?
This guide provides a foundational understanding of cloud infrastructure and server management. If you encounter any issues, feel free to leave a comment!

