How to Install Nginx on Ubuntu 20.04 – Google Cloud. Nginx is high performance light-weight HTTP and reverse proxy web server capable of handling large websites.
In this guide you are going to learn how to install Nginx on Ubuntu 20.04 and configure Firewall.
This setup is tested on Google Cloud so you can try this setup on any cloud servers like AWS, Azure or any VPS or dedicated servers.
Prerequisites
- Your Compute Engine Instance running.
- For setting up Compute Engine, see the Setting up Compute Engine Instance with Ubuntu 20.04.
Install Nginx
Let’s start by updating the local package index with the following command.
sudo apt update
sudo apt upgrade
Nginx is available in the Ubuntu 20.04 repositories by default, so you can install Nginx directly using the apt
command.
sudo apt install nginx
This will install Nginx and all required dependencies.
Configure Firewall
Now you can set up Uncomplicated Firewall (UFW) with Nginx to allow public access on default web ports for HTTP
and HTTPS
sudo ufw app list
You will see all listed applications.
Output
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
- Nginx Full: This opens both port
80
(normal, unencrypted web traffic) and port443
(TLS/SSL encrypted traffic) - Nginx HTTP: This opens port
80
(normal, unencrypted web traffic) - Nginx HTTPS: This profile opens only port
443
(TLS/SSL encrypted traffic) - OpenSSH: This profile opens port
22
for SSH access.
If you are not going to use SSL you need to enable only the Nginx HTTP.
Now we will enable Nginx Full.
sudo ufw allow 'Nginx Full'
With this command you can view the status of UFW.
sudo ufw status
You will see the output as follows.
Output
Status: active
To Action From
-- ------ ----
Nginx Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
Nginx Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)
Check Nginx Installation
Once Nginx is installed it will be started automatically and already be up and running.
Every process in Nginx is managed with the systemctl
or service
command.
Check the status of Nginx with the following command.
sudo systemctl status nginx
Output
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-05-01 10:47:23 UTC; 8s ago
Docs: man:nginx(8)
Main PID: 3762 (nginx)
Tasks: 2 (limit: 682)
Memory: 5.0M
CGroup: /system.slice/nginx.service
├─3762 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─3763 nginx: worker process
Now if you check the External IP address of your VM instance, you will see the default Nginx welcome page.
Common Nginx Commands
To start Nginx web server.
sudo systemctl start nginx
To stop Nginx webserver.
sudo systemctl stop nginx
To restart Nginx web server.
sudo systemctl restart nginx
To check Nginx configuration.
sudo nginx -t
Prepare yourself for a role working as an Information Technology Professional with Linux operating system
Conclusion
Now you have learned how to install Nginx on Ubuntu 20.04.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.
Leave a Reply
You must be logged in to post a comment.