How To Install Nginx Web Server on Ubuntu 18.04 – This is a web server which can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. The software was created by Igor Sysoev and first publicly released in 2004. A company of the same name was founded in 2011 to provide support and Nginx plus paid software.
In this article we are going to discuss How To Install Nginx Web Server on Ubuntu 18.04. Before you begin this guide, you should have a regular, non-root user with sudo privileges configured on your server.
Apache and NGINX
The main difference between Apache and NGINX lies in their design architecture. Apache uses a process-driven approach and creates a new thread for each request. Whereas NGINX uses an event-driven architecture to handle multiple requests within one thread.
Step 1 – Installing Nginx
Nginx is available in Ubuntu’s default repositories, it is possible to install it from Ubuntu repositories using the apt packaging system. We will update our local package index so that we have access to the most recent package listings. Afterwards, we can install Nginx
$ sudo apt update
$ sudo apt install nginx
Step 2 – Configuring the Firewall
Before testing Nginx, the Ubuntu firewall needs to be adjusted to allow access to the web service. Nginx registers itself as a service with
ufw upon installation, making it straightforward to allow Nginx access.
$ sudo ufw app list
You can enable port 80 using below command since we are going to discuss http port (80).
$ sudo ufw allow 'Nginx HTTP'
You can verify the change by typing:
$ sudo ufw status
You should see HTTP traffic allowed as below
OpenSSH ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
Step 3 – Checking your Web Server
At the end of the installation process, Ubuntu 18.04 starts Nginx. The web server should already be up and running.
$ sudo systemctl status nginx
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 2019-11-17 16:08:19 UTC; 7 days ago
Main PID: 2339 (nginx)
Tasks: 2 (limit: 1153)
├─2339 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─2360 nginx: worker process
You can access the default Nginx landing page to confirm that the software is running properly by navigating to your server’s IP address. If you do not know your server’s IP address, you can get it a few different ways.
Please your server’s IP address, enter it into your browser’s address bar:
You should see the default Nginx landing page:
This page will show you that the Nginx web server running correctly on your system.
Step 4 – Managing the Process
Now that you have your web server up and running, let’s review some basic management commands.
To stop your web server, type:
$ sudo systemctl stop nginx
To start the web server when it is stopped, type:
$ sudo systemctl start nginx
To stop and then start the service again, type:
$ sudo systemctl restart nginx
Reload without dropping connections.
$ sudo systemctl reload nginx
Enable or disable web server behavior
$ sudo systemctl disable nginx
$ sudo systemctl enable nginx
Please visit Nginx documentation site for more information