Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
In Nginx Last updated: September 6, 2022
Share on:
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

A step-by-step guide to installing Nginx on UNIX platforms.

Nginx was released in 2004 and since then growing rapidly. It holds more than 30% market share in web servers.


Let’s take a look at the installation procedure for various UNIX distro.


  • Ensure you are logged in as a root
  • Execute the following command
apt-get install nginx

It will take few seconds to install.


As usual, log in as a root and use the below yum command

yum install nginx

If using RHEL 8 then you may also use dnf command.

dnf install nginx

It will install including the dependencies. Below snapshot from CentOS.

  nginx.x86_64 0:1.10.2-1.el6                                                                                                      
Dependency Installed:
  GeoIP.x86_64 0:1.6.5-1.el6                                          GeoIP-GeoLite-data.noarch 0:2018.01-1.el6                   
  GeoIP-GeoLite-data-extra.noarch 0:2018.01-1.el6                     fontconfig.x86_64 0:2.8.0-5.el6                             
  freetype.x86_64 0:2.3.11-17.el6                                     gd.x86_64 0:2.0.35-11.el6                                   
  geoipupdate.x86_64 0:2.2.1-2.el6                                    libXpm.x86_64 0:3.5.10-2.el6                                
  libxslt.x86_64 0:1.1.26-2.el6_3.1                                   nginx-all-modules.noarch 0:1.10.2-1.el6                     
  nginx-filesystem.noarch 0:1.10.2-1.el6                              nginx-mod-http-geoip.x86_64 0:1.10.2-1.el6                  
  nginx-mod-http-image-filter.x86_64 0:1.10.2-1.el6                   nginx-mod-http-perl.x86_64 0:1.10.2-1.el6                   
  nginx-mod-http-xslt-filter.x86_64 0:1.10.2-1.el6                    nginx-mod-mail.x86_64 0:1.10.2-1.el6                        
  nginx-mod-stream.x86_64 0:1.10.2-1.el6                        

Installation Using Source Code

If your server doesn’t have Internet connectivity or working on the DMZ server, then you can compile from source code to install it.

The following demonstration is from CentOS/RHEL.

  • Extract the downloaded file
gunzip –c nginx-1.12.2.tar.gz | tar xvf –
  • After extract, you should see the following files and folders
[root@instance-4 nginx-1.12.2]# ls -ltr
-rw-r--r--. 1 chandan scorpio_ckumar     49 Oct 17 13:16 README
-rw-r--r--. 1 chandan scorpio_ckumar   1397 Oct 17 13:16 LICENSE
-rwxr-xr-x. 1 chandan scorpio_ckumar   2481 Oct 17 13:16 configure
-rw-r--r--. 1 chandan scorpio_ckumar 423948 Oct 17 13:16
-rw-r--r--. 1 chandan scorpio_ckumar 278202 Oct 17 13:16 CHANGES
drwxr-xr-x. 9 chandan scorpio_ckumar     91 Feb  3 03:11 src
drwxr-xr-x. 2 chandan scorpio_ckumar     21 Feb  3 03:11 man
drwxr-xr-x. 2 chandan scorpio_ckumar     40 Feb  3 03:11 html
drwxr-xr-x. 4 chandan scorpio_ckumar     72 Feb  3 03:11 contrib
drwxr-xr-x. 2 chandan scorpio_ckumar    168 Feb  3 03:11 conf
drwxr-xr-x. 6 chandan scorpio_ckumar   4096 Feb  3 03:11 auto
[root@instance-4 nginx-1.12.2]#

Now, we are ready to configure and install it.

You can control the installation location using --prefix=path parameter.

Let’s install under /opt/nginx with the SSL module.

./configure --prefix=/opt/nginx --with-http_ssl_module 
make install

Note: if you are doing this on a brand new server where the compiler is not installed then you got to install the following.

yum install gcc pcre-devel openssl-devel

Upon completion, you should see nginx is installed under /opt/nginx with the following folders.

[root@instance-4 nginx]# ls -ltr
drwxr-xr-x. 2 root root   19 Feb  3 03:19 sbin
drwxr-xr-x. 2 root root 4096 Feb  3 03:19 conf
drwxr-xr-x. 2 root root    6 Feb  3 03:19 logs
drwxr-xr-x. 2 root root   40 Feb  3 03:19 html
[root@instance-4 nginx]#

Congratulation, You have just installed Nginx!

Stop and Start Procedure

If you compiled using the source code then to start

  • Go to sbin folder and execute nginx

To stop

./nginx –s stop

If installed using repository then

service nginx start 
service nginx stop

What next?

If this is for production then do necessary hardening and security configuration and if exploring to learn then check out this online course.

  • Chandan Kumar
    As the founder of Geekflare, I’ve helped millions to excel in the digital realm. Passionate about technology, I’m on a mission to explore the world and amplify growth for professionals and businesses alike.
Thanks to our Sponsors
More great readings on Nginx
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • is an all-in-one work OS to help you manage projects, tasks, work, sales, CRM, operations, workflows, and more.
    Try Monday
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder