Javatpoint Logo
Javatpoint Logo

Installing NGINX on Debian/Ubuntu

There are two ways to install NGINX:

  • Using a pre-built binary: - This method is much easiest and faster method.
  • Building it up from source: - This method provides the ability to include various third-party modules that make Nginx even more powerful.

Following are the steps which will show us how to install Nginx on our Debian or Ubuntu system:

Step 1: First of all, let's update our local package index so that we have access to the most recent package listings.

Open the terminal on Ubuntu or Debian and run the following command to ensure that all packages on the OS are up to date:


How to Install NGINX on Debian/Ubuntu

Since Nginx is available in the default repository of Debian or Ubuntu, it is possible to install it from these repositories using the apt packaging system.


How to Install NGINX on Debian/Ubuntu

Once it is done, use the following command to see the process for the webserver in a running state.


How to Install NGINX on Debian/Ubuntu

Adjusting the firewall to access Nginx

For accessing the Nginx from the web server, we have to allow access to the services from outside.

To see the list of profiles available to allow from the firewall, use the following command:

How to Install NGINX on Debian/Ubuntu

Here,

Nginx Full: It allows both ports 80 and 443.

Nginx HTTP: It allows only the port 80.

Nginx HTTPS: It allows only port 443.

To allow both ports HTTP 80 and HTTPS 443 then use the following command:

To allow only Nginx HTTP port 80 use the following command:


How to Install NGINX on Debian/Ubuntu

To allow only Nginx HTTPS port 443, use the following command:

Checking the NGINX Service Status

By default, after the installation of Ubuntu, the Nginx starts automatically and we can check the status of the Nginx with the help of the following command:

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 Mon 2016-04-18 16:14:00 EDT; 4min 2s ago

Main PID: 12857 (nginx)

CGroup: /system.slice/nginx.service

├─12857 nginx: master process /usr/sbin/nginx -g daemon on; master_process on

└─12858 nginx: worker process


How to Install NGINX on Debian/Ubuntu

We can see from the above, the service appears to have started successfully. However, the best way to test this is to request a page from Nginx.

We can access the default Nginx page to make sure that the software is running properly. We can access this through our server's domain name or IP address. Or we can use http://localhost on Windows.

We should see the "Welcome to Nginx" default page. If we see that page, then we can be sure that Nginx has been installed properly.

How to Install NGINX on Debian/Ubuntu

This page is normally included with Nginx to show us that the server is running properly.






Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA