NGINX is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. NGINX is a free and open source software licensed under 2-clause BSD.
You can easily download and use NGINX in Windows, macOS, Linux and other operating systems link read NGINX installation instructions from the official docs and install on your operating system for free.
But, in this blog we are going to build NGINX from source code. And we will configure NGINX’s settings, paths, and add or remove modules.
So let’s get started…
We’ll use Ubuntu 20.04 LTS as our operating system, though these instructions are applicable to other Linux-based systems as well.
Start by visiting the NGINX download page and choose either the stable release or the mainline version for experimental features. For example, you can download nginx-1.21.4.
Link: NGINX download page.
Note: You can use
curl to download.
After downloading, extract the tar file using:
tar -zxvf nginx-1.21.4.tar.gz
Now cd into
Ensure you have the necessary build tools. On Ubuntu, use
apt package manager:
sudo apt install build-essential
Additionally, install required dependencies and libraries:
sudo apt install libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
Check all configuration options:
sudo ./configure --help
Refer to the NGINX documentation’s module reference section for details on modules. Configure installation paths and modules as needed.
Follow the link: nginx docs > module reference section
sudo ./configure \
Compile NGINX by running:
# Run below command to install NGINX
Reload NGINX to apply changes:
nginx -s reload
If you encounter an error related to the nginx.pid file missing, follow these steps:
nginx: [error] open() “/var/run/nginx.pid” failed (2: No such file or directory)
5.1. Add Nginx as service:
Add NGINX as a service by creating a systemd config file. Create or modify
/lib/systemd/system/nginx.service with appropriate paths:
Visit: nginx systemd config and create the file.
Change pid and sbin path as set in step 3.
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
ExecReload=/usr/bin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
5.2. Start NGINX using systemd:
sudo systemctl start nginx
5.3. Enable NGINX to start on boot:
sudo systemctl enable nginx
That’s all you need to do to compile and run NGINX on Ubuntu.
If you get any error or suggestion please leave a comment.
Happy NGINX-ing! 🤟comments powered by Disqus