Installing and configuring Nginx web server from source will give you more benefits than the prebuilt Nginx packages, such as installing Nginx via your OS distribution repository. If you’ve building Nginx from source you can add specific modules from Nginx and its third-party repository, like Elasticsearch, HTTP Redis2, GeoIP2 or HTTP Lua modules.

So, you will get more benefits rather than using default Nginx distribution repository. In order to configuring Nginx from source, you must install libraries for its software dependencies.

Before you doing that, don’t forget to add PCRE – Supports regular expressions, since this is required by the Nginx core and rewrite modules. Simply follow this snippet code command to add that extension to your system.

Please note, on this testing purpose, i am using Digital Ocean $5 droplets with Debian 10 (Buster).


* Server IPv4 Address
* Full Root Access
* Cloud Server with RHEL/Fedora/Centos or Debian/Ubuntu
* Gnome Terminal or PuTTy client

1.) Step one, before add PCRE to your virtual server, don’t forget to update your system first and install “make” as required software dependencies.

$ apt update
$ apt upgrade

Install and Configure Make, gcc+, and build-essential. This will install make and a C++ compiler.

$ apt install make gcc+ build-essential
$ apt install make-guile

And then, install PCRE to your Debian 10 machine.

$ wget
$ tar -zxf pcre-8.44.tar.gz
$ cd pcre-8.44
$ ./configure
$ make
$ sudo make install

Or using distribution software repository:

For Debian/Ubuntu Server
$ sudo apt-get install libpcre3 libpcre3-dev

For RHEL/CentOS/Fedora
$ yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel libssl-dev

2.) After that, you should add zlib extension (supports header compression) since this is required by the Nginx gzip module.

$ wget
$ tar -zxf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make
$ sudo make install

3.) Now you have PCRE and zlib extension installed on your Debian machine, so you need to install OpenSSL module (support HTTPS protocol). OpenSSL is must be installed since it will be using to run Nginx SSL module and any other modules.

$ wget
$ tar -zxf openssl-1.1.1g.tar.gz
$ cd openssl-1.1.1g
$ ./Configure darwin64-x86_64-cc --prefix=/usr
$ make
$ sudo make install

4.) On step 4, we will downloading Nginx from the source ( and then compiling this web server to your system. Please note, we have two options for installing Nginx, including stable or mainline branchs.

So, simply download and unpack latest Nginx mainline branch since mainline is more having new features, getting more frequently updates and major bugfixes compared to the stable branch.

Ok, let’s run this command to install Nginx mainline branch. I am will install nginx mainline on this tutorial.

$ wget
$ tar zxf nginx-1.19.6.tar.gz
$ cd nginx-1.19.6

Or if you want to run stable branch, simply run this command:

$ wget
$ tar zxf nginx-1.18.0.tar.gz
$ cd nginx-1.18.0

5.) Let’s configuring Nginx and you will have options to configure it with third-party modules using ./configure script to setting up various Nginx parameters.

./configure --prefix=/usr/share/nginx \
            --sbin-path=/usr/sbin/nginx \
            --modules-path=/usr/lib/nginx/modules \
            --conf-path=/etc/nginx/nginx.conf \
            --error-log-path=/var/log/nginx/error.log \
            --http-log-path=/var/log/nginx/access.log \
            --pid-path=/run/ \
            --lock-path=/var/lock/nginx.lock \
            --user=www-data \
            --group=www-data \
            --build=Debian \
            --http-client-body-temp-path=/var/lib/nginx/body \
            --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
            --http-proxy-temp-path=/var/lib/nginx/proxy \
            --http-scgi-temp-path=/var/lib/nginx/scgi \
            --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
            --with-openssl-opt=enable-ec_nistp_64_gcc_128 \
            --with-openssl-opt=no-nextprotoneg \
            --with-openssl-opt=no-weak-ssl-ciphers \
            --with-openssl-opt=no-ssl3 \
            --with-pcre=../pcre-8.44 \
            --with-pcre-jit \
            --with-zlib=../zlib-1.2.11 \
            --with-compat \
            --with-file-aio \
            --with-threads \
            --with-http_addition_module \
            --with-http_auth_request_module \
            --with-http_dav_module \
            --with-http_flv_module \
            --with-http_gunzip_module \
            --with-http_gzip_static_module \
            --with-http_mp4_module \
            --with-http_random_index_module \
            --with-http_realip_module \
            --with-http_slice_module \
            --with-http_ssl_module \
            --with-http_sub_module \
            --with-http_stub_status_module \
            --with-http_v2_module \
            --with-http_secure_link_module \
            --with-mail \
            --with-mail_ssl_module \
            --with-stream \
            --with-stream_realip_module \
            --with-stream_ssl_module \
            --with-stream_ssl_preread_module \
            --with-debug \
            --with-mail=dynamic \
            --without-http_empty_gif_module \
            --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' \
            --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now'

6.) On step 6, let’s compile and install the nginx build from source in order to completing installation from source.

* Compile and install:

$ make
$ sudo make install

After Nginx installation is completed, don’t forget to start Nginx web server.

Using systemd command for RHEL/Fedora/CentOS or Debian/Ubuntu server

$ systemctl start nginx.service

OR using service command

$ service nginx start

Conclusion, building Nginx from source is quite easy and you will get more benefits rathet than installing Nginx from your system repository. You just have relax time to doing the test.


Please enter your comment!
Please enter your name here