Introduction
I have always wanted to share my learning experiences and knowledge from my tasks and projects. In this article, as part of the HNG Internship program, I will provide a step-by-step guide on configuring a simple Nginx web server on a Google Compute Engine Ubuntu virtual machine.
Requirements
- A Google Cloud account, if you don't have an account, Sign up. GCP is giving free $300 credits to new accounts.
- Basic experience with Linux CLI.
- Sign in to your Google Cloud console.
Steps on how to set up an Ubuntu Virtual Machine.
Step 1
- Click on the three bars by the left side of the console.
Step 2
- Click on Compute Engine and then clickon VM Instances
Step 3
- Click on "Create" Instance.
Step 4: Machine Configuration settings
- Give the instance any name of your choice.
- Choose the region and zone nearest to you for your instance.
- Choose the default General Purpose E2 machine for the task.
Step 5: Operating System and Storage
- Continue the instance setup by clicking on OS and Storage.
- Click "Change" in the Operating System configuration.
- Change the OS image to Ubuntu and keep the remaining settings as default.
- Click "Select".
Step 6: Networking
For the firewalls, tick to allow HTTP and HTTPS traffic.
Click on "create" instance
Congratulations! You have successfully launched a Google Cloud Virtual Instance.
To SSH Into The Nginx Virtual Instance.
- On the instance dashboard, Tick the instance and click on "SSH" A new window pops up.
- Click "Authorize" to connect to the instance. And wait for SSH to connect to the instance successfully.
Good Job! You are now connected to your Instance Command Line interface.
How to Configure Nginx on Ubuntu Virtual Instance
Step 1: Run the command below to Update and Upgrade the Instance.
sudo apt update & sudo apt upgrade -y
Step 2: Install Nginx
sudo apt install nginx -y
Step 3: Start and Enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
Step 4: Check if Nginx is actively running successfully
sudo systemctl status nginx
Step 5: Back up the Default Web Page
cd /var/www/html
sudo cp index.nginx-debian.html index.nginx-debian.html.bk
Step 6: Create a new file named index.html
touch index.html
Step 7: Move the content of the default page to the new file
sudo mv index.nginx-debian.html index.html
Step 8: Open the index.html file
sudo vi index.html
Step 9: Modify the content of index.html file to the code below
- To edit the file, press the letter "i"
<!DOCTYPE html>
<html>
<head>
<title>HNG Stage 0 Nginx Web Server</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h4>Welcome to DevOps Stage 0 - [Your Name]/[SlackName] </h4>
</body>
</html>
- After editing, press the escape key, colon, letters w and q. That is, ":wq"
Step 10: Restart Nginx
sudo systemctl restart nginx
Step 10: Copy the External Ip address and paste in your browser
34.89.121.56
Possible Challenges
One potential challenge you may face when accessing your webpage is related to networking. Ensure that the firewall is configured to allow inbound HTTP traffic, as the NGINX server listens on port 80 by default.
How This Task Contributed to My Learning
As someone with extensive experience using AWS Cloud, I wanted to enhance my multi-cloud skills by leveraging Google Cloud as my development environment for this task. Previously, I primarily accessed virtual instances by clicking the SSH option on the Google Cloud Console. However, during this task, I explored alternative methods of connecting to a GCP instance using PuTTY, Git Bash, and other SSH tools.
This was particularly exciting for me because, on AWS, I have always accessed EC2 instances by downloading and using the private key. Through this experience, I learned how to generate private and public key pairs using PuTTY, add the public key to the GCP instance's SSH configuration, and securely authenticate my connection.
In a forthcoming article, I will share a step-by-step guide on connecting to a GCP instance using third-party SSH tools and also generating keys through the command line.
Hire your skilled DevOps Engineers and Cloud Engineers here.
Top comments (0)