Operations 3 min read

Step-by-Step Guide to Building and Deploying Nginx from Source on Linux

This tutorial walks you through downloading the Nginx source package, extracting it, compiling and installing the binary, setting up the required directories, creating a systemd service file, and finally enabling and starting the Nginx service on a Linux system.

Raymond Ops
Raymond Ops
Raymond Ops
Step-by-Step Guide to Building and Deploying Nginx from Source on Linux

First, change to the /opt directory and download the Nginx 1.18.0 source archive:

cd /opt
wget http://nginx.org/download/nginx-1.18.0.tar.gz

Extract the archive: tar xf nginx-1.18.0.tar.gz Create the installation directory and compile Nginx:

cd nginx-1.18.0
./configure --prefix=/apps/nginx
make && make install

After compilation, create a symbolic link to the binary if needed and copy any additional configuration files.

Next, create a systemd service unit file (e.g., /etc/systemd/system/nginx.service) with the following content:

[Unit]
Description=The nginx HTTP and reverse proxy server

[Service]
PIDFile=/apps/nginx/logs/nginx.pid
ExecStart=/apps/nginx/sbin/nginx
ExecStop=/usr/bin/kill -s TERM $MAINPID
ExecReload=/apps/nginx/sbin/nginx -s reload

[Install]
WantedBy=multi-user.target

Reload systemd to recognize the new unit, then start and enable Nginx:

systemctl daemon-reload
systemctl start nginx
systemctl enable nginx
systemctl status nginx

These commands verify that Nginx is running correctly and will start automatically on boot.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxsystemdSource Compilation
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.