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.
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.gzExtract 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 installAfter 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.targetReload systemd to recognize the new unit, then start and enable Nginx:
systemctl daemon-reload
systemctl start nginx
systemctl enable nginx
systemctl status nginxThese commands verify that Nginx is running correctly and will start automatically on boot.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
