NGINX is open-source software for web serving, Nginx is one of the most popular web servers in the world. It’s a lightweight and robust web server that is mostly used in hosting high-traffic websites.
In this guide, we are going to install the Nginx web server and are going to configure the Nginx server block. It’s super easy to do so let’s just get into it.
A system running Ubuntu 20.04 Linux
A user account with sudo or root privileges
A stable internet connection is recommended to install Nginx packages.
Step 1 – Update The Packages
Before installing anything it is always recommended to update the packages. And this command will update all your packages.
$ sudo apt update
Step 2 – Install Nginx
Install Nginx with the following command.
$ sudo apt install nginx
Then you will get the prompt to continue, press ‘Y’ on the keyboard, and hit ENTER. After that Nginx will get installed on your system.
Step 3 – Verify Installation
After the installation, Nginx automatically starts on your system. To check if Nginx is successfully installed on the system use the following command.
$ sudo systemctl status nginx
After running this command you should see the active (running) status which means you are good to go.
Step 4 – Setup Firewall
Now we are going to change our firewall setting to allow traffic to our NGINX server from various HTTP and non-HTTP web servers on port 443, 80, or both of these ports. For now, we will only need to allow traffic on port 80. To grant Nginx access through the default Ubuntu firewall, enter the following command.
$ sudo ufw allow ‘nginx http’
Also, use this command to refresh the new firewall settings.
$ sudo ufw reload
Step 5 – Test The Server
Now make sure Nginx is running as shown in step 3 and then open any of your browser and navigate to the following URL
You should see “Welcome to Nginx!” on your browser as shown in the image below. This means Nginx is running successfully on your system.
Step 6 – Basic Commands
Now that you have successfully installed and run a Nginx server on your system you should know some basic management commands to properly run the system in the future.
To stop your web server, use the following command:
$ sudo systemctl stop nginx
To start the web server when it is stopped, use the following command:
$ sudo systemctl start nginx
To restart the service again, use the following command:
$ sudo systemctl restart nginx
To reload the Nginx use the following command:
$ sudo systemctl reload nginx
When you first install the Nginx by default, Nginx is set to start automatically when the server boots. If you want to disable this behavior by using the following command:
$ sudo systemctl disable nginx
To re-enable start up at boot, you can use the following command:
$ sudo systemctl enable nginx
These are some basic sets of commands which will help you manage your Nginx server after installing this on your system.
Uninstall Nginx server
Now you have learned to install the Nginx let’s know how you can uninstall this from your system. Use the following command to uninstall Nginx
$ sudo apt purge nginx
After that to remove other Nginx related unnecessary packages use the following command.
$ sudo apt autoremove
To reinstall Nginx you need to first uninstall the current Nginx like we have shown you above and Install again as we have mentioned in this article above.