DEV Community

Qowiyyu Adelaja
Qowiyyu Adelaja

Posted on

Installing NGINX on GCP (Google Cloud Platform)

Introduction

I have always wanted to expand my skills from backend to cloud computing and DevOps. Knowing the nitty-gritty of how the infrastructure that facilitates software deployment has always fascinated me; hence, I joined the HNG internship.

As a finalist of HNG 10 when my focus was on becoming a finalist, this time I want to have fun and make a lot of techie friends while picking up DevOps skills and becoming a finalist.

The first task was setting up and configuring NGINX on a fresh Ubuntu server with the default HTML page overridden, so I decided to explore Google Cloud Platform (GCP) by creating a virtual machine (VM). Here's how I did it, the challenges I faced, and how this boosted my confidence in using GCP.

Task Overview

  1. Create a VM on GCP.
  2. SSH into the VM using gcloud.
  3. Install nginx on the VM
  4. Configure the firewall to accept HTTP and HTTPS.
  5. Change the default html page.
  6. Restart nginx.

1. Create a VM on GCP

I created a Google cloud account and logged into the Google cloud console Google cloud console.
On creating the account, press the Create a VM > Enable Compute Engine API > Create VM Instances. Configure the VM instance with the settings below:

Name: simple-nginx-configuration
Region/Zone: europe-west1-d
Machine Type: e2-micro (free tier)
Boot Disk: Ubuntu 20.04 LTS
Firewall: Enabled HTTP and HTTPS traffic

2. SSH into the VM

To SSH into the VM, download the gcloud tool using the official guide

Then I authenticated using

gcloud auth login

Then I configured the project ID

gcloud config set project [project_id]

NB: Replace the project_id with your project_id

Then I SSH into the VM using

gcloud compute ssh [INSTANCE_NAME] --zone [zone]

3. Install nginx on the VM

Update the package list

sudo apt update

Enter fullscreen mode Exit fullscreen mode

Install nginx

sudo apt install nginx

Enter fullscreen mode Exit fullscreen mode

Verify the installation

nginx -v

Enter fullscreen mode Exit fullscreen mode

Start nginx

sudo systemctl start nginx
Enter fullscreen mode Exit fullscreen mode

Enable nginx

sudo systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

Check nginx status

sudo systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

NB: You will see running if the service is active/started

3. Configure the Firewall

Enable the firewall

sudo ufw enable

Allow HTTP

sudo ufw allow 'Nginx HTTP'

Allow HTTPS

sudo ufw allow 'Nginx HTTPS'

Allow SSH

sudo ufw allow 'OpenSSH'

Verify firewal rules

sudo ufw status

4. Change Default HTML Page

Open the html page using vi or nano (I used nano), edit and save it

sudo nano /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode
<!DOCTYPE html>
<html>
<head>
    <title>Welcome</title>
</head>
<body>
    <h1>Welcome</h1>
    <p>Welcome to DevOps Stage 0 - [Your Name]/[SlackName]</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

I ensured the file has the correct permission

sudo chown -R www-data:www:data /var/www/html
sudo chmod -R 755 /var/www/html
Enter fullscreen mode Exit fullscreen mode

5. Restart nginx

Restart nginx to reflect the changes

sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Open the webpage in a browser using http://[your ip address]. You should see content of the html page

How This Task Contributes to My Learning and Professional Goals

This task was a hands-on experience that deepened my understanding of creating and managing VM instances on GCP and configuring a web server(nginx).

References

Here are some roles that HNG can provide engineers for:

DevOps Engineers
Cloud Engineers
Site Reliability Engineers
Platform Engineers
Infrastructure Engineers
Kubernetes Specialists
CI/CD Pipeline Engineers
Monitoring/Observability Engineers
Docker Specialists

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs