Installing Nginx From Source
In this post I will walk your through the introduction & the step by step procedure of compiling & installing Nginx on ubuntu server from source code
What is Nginx
Nginx is an open source & powerful software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It was developed by the Russian developer Igor Sysoev back in 2004. Igor Sysoev originally wrote Nginx to solve the C10K problem.
Besides its server capabilities, Nginx can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers. NGINX was created as Fastest Web-Server to serve the concurrent large number of requests.
Nginx supports micro services to HTTP/2 protocols. It is also container friendly, which makes it first choice for cloud based applications & deploying load balancers.
Downloading
I’m using Ubuntu 22.04 LTS for the demonstration. Visit the official page of Nginx and from the mainline section copy the download link of the source archive to clipboard.
Lauch your terminal and download the tarball using wget
wget https://nginx.org/download/nginx-1.25.3.tar.gz
To extract the .tar.gz archive run this command:
tar -zxvf nginx-1.25.3.tar.gz
Navigate into the extracted directory
cd nginx-1.25.3
Compiling
In order to compile the Nginx from source code we need build-essential package and other dependencies and libraries. Let us install them in two steps:
sudo apt-get install build-essential -y
Installing other dependencies
sudo apt-get install libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev make
Make sure you are inside the nginx-1.25.3 directory & run:
./configure --sbin-path=/usr/bin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-pcre --pid-path=/var/run/nginx.pid --with-http_ssl_module
It configures the nginx build process with specific options and paths. It specifies the location of the nginx executable, configuration file, error and access logs, and the use of the PCRE library and HTTP SSL module. It also sets the location of the nginx process ID file.
Make & Build
The make command is used to compile and build software from source code. It reads instructions from a Makefile and executes them to create an executable program. Run the below command to generate a make file.
sudo make
To execute the Makefile run:
sudo make install
The make install command is used to install the compiled program and its associated files onto the system. This typically involves copying the executable to the appropriate location, setting permissions, and creating any necessary configuration files.
Now to verify the successful installation of nginx run nginx -v
It will return the nginx version installed on your machine.
To start the Nginx server run sudo nginx
. Visit your IP in your browser you should see the Welcome page of Nginx server.
Closing Note
There are other alternate, oneliners & easier methods to install Nginx, for example using package managers. However, installing it from source code allows for greater customization and flexibility in configuring the web server.
This means that we can tailor the installation to our specific needs and requirements, rather than using a pre-packaged version with fixed settings.
Moreover, it allows users to access the latest features and updates that may not be available in pre-packaged versions. We also get to control over which modules are included and can ensure that the latest security patches are applied.
That is all for today. If you found this post useful consider sharing it with friends & subscribe using RSS or Telegram.
Reply via mail