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
- 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 install nginx
If using RHEL 8 then you may also use
dnf install nginx
It will install including the dependencies. Below snapshot from CentOS.
Installed: 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.
- Download the latest version of Nginx source code and transfer to the server.
- Extract the downloaded file
gunzip –c nginx-1.12.2.tar.gz | tar xvf –
- After extract, you should see the following files and folders
[[email protected] 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 CHANGES.ru -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 [[email protected] nginx-1.12.2]#
Now, we are ready to configure and install it.
You can control the installation location using
Let’s install under
/opt/nginx with the SSL module.
./configure --prefix=/opt/nginx --with-http_ssl_module make 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.
[[email protected] 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 [[email protected] 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
./nginx –s stop
If installed using repository then
service nginx start service nginx stop
More great readings on Nginx
How to Redirect AMP Page to Non-AMP in Nginx, Apache, Cloudflare?Abhishek Nair on September 27, 2021
How to Block .git in Apache, Nginx and Cloudflare?Chandan Kumar on October 27, 2020
How to Protect Page with Password in Apache, Nginx, WordPress, Hosting?Chandan Kumar on September 11, 2020
How to Implement ZeroSSL Certificate in Apache and Nginx?Asad Ali on May 24, 2020
Configuring Nginx for Performance and SecurityMichael Aboagye on February 24, 2020
How to Enable CORS in Apache and Nginx?Chandan Kumar on October 18, 2019
Join Geekflare Newsletter
Every week we share trending articles and tools in our newsletter. More than 10,000 people enjoy reading, and you will love it too.