Tutorials  /  Linux Basics

Build NGINX from Source on CentOS with OpenSSL & PCRE

Ccentron Redaktion · June 2025 ·5 min read ·Linux Basics, Tutorial

NGINX is a high-performance tool that can function as an HTTP/HTTPS server, reverse proxy, mail proxy, load balancer, TLS termination point, or a caching engine. Its architecture is modular, supporting both built-in and third-party extensions. As it's developed in C, it delivers excellent speed and low memory usage.

Version Types of NGINX

NGINX maintains two concurrent release branches: the mainline and the stable versions. Either can be deployed on production environments, though the mainline release is generally recommended for its up-to-date features.

VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Overview of Installation from Source

The process of installing NGINX from its source code is straightforward. Simply download the latest version, configure it according to your needs, compile the source, and then install it. This tutorial demonstrates the installation using the mainline version 1.13.2. If newer versions are available, ensure you update the version numbers accordingly.

Essential Prerequisites for Compiling NGINX

Mandatory Components:

  • OpenSSL library version ranging from 1.0.2 to 1.1.0
  • zlib compression library, version 1.1.3 through 1.2.11
  • PCRE (Perl Compatible Regular Expressions), between version 4.4 and 8.40
  • GCC compiler suite

Optional Components:

  • PERL language support
  • libatomic_ops library
  • LibGD image processing library
  • MaxMind GeoIP library
  • libxml2 XML parser
  • libxslt XSLT processor

Initial Preparation Steps

Before proceeding with the installation process, carry out the following preliminary tasks:

Create a Sudo-Enabled User Account

Begin by setting up a non-root user account with administrative privileges.

Switch to the New User

Code
su - <username>

Update the Operating System

Console
sudo yum check-update || sudo yum update -y

How to Build and Install NGINX from Source on CentOS

Install Required Development Tools

Start by installing the necessary development packages along with the Vim text editor:

Console
sudo yum groupinstall -y 'Development Tools' && sudo yum install -y vim

Enable EPEL Repository

Install the Extra Packages for Enterprise Linux (EPEL) repository:

Console
sudo yum install -y epel-release

Install Optional Dependencies

Install optional packages required by NGINX:

Console
sudo yum install -y perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel

Download and Unpack NGINX Source Code

Fetch the mainline version and extract it:

Console
wget https://nginx.org/download/nginx-1.13.2.tar.gz && tar zxvf nginx-1.13.2.tar.gz

Download Required Libraries

NGINX relies on PCRE, zlib, and OpenSSL. Download and extract their sources:

Console
# PCRE version 8.40
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz && tar xzvf pcre-8.40.tar.gz

# zlib version 1.2.11
wget https://www.zlib.net/zlib-1.2.11.tar.gz && tar xzvf zlib-1.2.11.tar.gz

# OpenSSL version 1.1.0f
wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz && tar xzvf openssl-1.1.0f.tar.gz

Clean Up Archive Files

Code
rm -rf *.tar.gz

Change Directory and Inspect

Console
cd ~/nginx-1.13.2
ls
# auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

Install the NGINX Manual Page

Console
sudo cp ~/nginx-1.13.2/man/nginx.8 /usr/share/man/man8
sudo gzip /usr/share/man/man8/nginx.8
man nginx

Review Configure Options

Code
./configure --help
./configure --help | grep -F =dynamic

Configure, Compile and Install

Code
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--user=nginx \
--group=nginx \
--build=CentOS \
--builddir=nginx-1.13.2 \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre=../pcre-8.40 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.1.0f \
--with-openssl-opt=no-nextprotoneg \
--with-debug

make 
sudo make install
Console
sudo ln -s /usr/lib64/nginx/modules /etc/nginx/modules

Verify Build and Version

Console
sudo nginx -V

Create NGINX User and Validate Config

Console
sudo useradd --system --home /var/cache/nginx --shell /sbin/nologin --comment "nginx user" --user-group nginx
sudo nginx -t
sudo mkdir -p /var/cache/nginx && sudo nginx -t

Create systemd Service File

Console
sudo vim /usr/lib/systemd/system/nginx.service

Paste the following configuration:

Code
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

Start and Enable NGINX

Console
sudo systemctl start nginx.service && sudo systemctl enable nginx.service
sudo systemctl is-enabled nginx.service
sudo systemctl status nginx.service
ps aux | grep nginx
curl -I 127.0.0.1

Reboot and Cleanup

Console
sudo shutdown -r now
sudo rm /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf

Enable NGINX Syntax Highlighting in Vim

Console
mkdir ~/.vim/
cp -r ~/nginx-1.13.2/contrib/vim/* ~/.vim/

Remove Default Configuration Backups

Console
sudo rm /etc/nginx/*.default

Conclusion

And that's a wrap. You’ve now installed the latest NGINX release successfully. This version is statically linked to crucial libraries such as OpenSSL. Since operating systems often ship with outdated OpenSSL packages, compiling it this way allows you to benefit from recent enhancements. This includes support for advanced encryption methods like CHACHA20_POLY1305 and newer protocols such as TLS 1.3, which will be introduced in OpenSSL 1.1.1 (still pending release at the time this was written).

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren