It is a very well-known web server effectively used across the globe to host web platforms having a larger amount of traffic.
Sometimes the webserver is much more result-oriented than Apache and developers prefer to work on Nginx rather than Apache. Also, the exciting feature of Nginx is that one can use it as a reverse proxy server as well.
Here, we will learn how to install Nginx in Ubuntu. So, if you are the one browsing for the same, you are at the right place. So, let’s get started.
Before entering the installation steps, if you understand the prerequisites, it will be beneficial.
So, in order to start the configuration, one must have a regular and non-root user having ‘sudo’ privileges at the working server.
Nginx is already available in the default repository of Ubuntu. So you should it by using “apt” packaging system. Furthermore, do not forget to update the local package index.
As here, the first communication is made with “apt” so the step is required. It helps in accessing the recent packages. Once it is done, you should install “Nginx”.
sudo apt update sudo apt install nginx
Now, Nginx is installed by “apt” and other important dependencies for the server.
Adjustment of firewall is important before heading towards the testing of Nginx. It allows access to the required services. On installation, Nginx registers as a service along with “ufw” which further helps in getting Nginx access.
Now you should list the configurations known to “ufw” by following the given code.
sudo ufw app list
Now, having three profiles the output of the command will be available as Output
Available applications: Nginx Full Nginx HTTP Nginx HTTPS OpenSSH
Significance of the three profiles:
Depending upon the traffic configured one can enable from the given profiles. In order to enable Nginx HHTPS, the SSL configuration is a must. If you do not have an SSL configuration, you should enable Nginx HTTP that will allow traffic on port 80 only.
Follow the code to enable the profile sudo ufw allow ‘Nginx HTTP’
Verification of the changes can be checked using the code: sudo ufw status
The Output will be shown as:
Output Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx HTTP ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx HTTP (v6) ALLOW Anywhere (v6)
Examination of the webserver is important and make sure it should be in a ready and running position. The assurance of the system can be checked using the command “systemd”. Follow the code to check your webserver
systemctl status nginx
The output will be shown as:
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 Fri 2018-04-20 16:08:19 UTC; 3 days ago Docs: man:nginx(8) Main PID: 2369 (nginx) Tasks: 2 (limit: 1153) CGroup: /system.slice/nginx.service ├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; └─2380 nginx: worker process
The above output speaks that the process is successful. Also, you can make assurance by requesting a page from Nginx. A default landing page of Nginx will confirm whether the software is running properly or not. It will also verify the navigation of the server’s IP address.
For those who are unable to know the IP address, here are the ways to get it done. Write the given at the server’s command prompt:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
In return for the given commands, few lines will be shown. Now, one should try these lines on the web browser and verify if it runs or not.
Alternative code to know the IP Address is
curl -4 icanhazip.com
Out will be shown as http://your_server_ip
In the above step, we have seen that our web server is good and running properly. Now here are few things that should be verified. We should know, how to manage the basic elements that take part in the configuration.
Let’s have a look at commands of basic management:
1.How to stop and start the webserver?
Follow the given code to stop the webserver sudo systemctl stop nginx
Follow the given code to start the webserver sudo systemctl start nginx
2. How to restart the service?
Follow the given code to stop the webserver sudo systemctl restart nginx
3.Other required management
During configuration changes, if you want Nginx should reload them without losing the connections, follow the given code.
sudo systemctl reload nginx
To disable the default behavior of Nginx i.e. it starts automatically whenever the server boots, you should follow the given code:
sudo systemctl disable nginx
In order to re-enable the above-mentioned service, the required command will be:
sudo systemctl enable nginx
Quick Links