Operations 3 min read

How to Compile and Deploy Nginx from Source on Linux

This guide walks through downloading the Nginx source package, extracting it, compiling and installing it to a custom directory, configuring a systemd service unit, and finally starting and verifying the server on a Linux system.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Compile and Deploy Nginx from Source on Linux

Experiment: compile and install Nginx from source.

cd /opt
wget http://nginx.org/download/nginx-1.18.0.tar.gz   # download the package to /opt
tar xf nginx-1.18.0.tar.gz   # extract the archive

After extraction, create the installation directory and copy files:

mkdir -p /apps/nginx
# copy binaries and configuration files to /apps/nginx
# make symbolic links as needed

Create a systemd service unit for Nginx:

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

[Service]
PIDFile=/apps/nginx/logs/nginx.pid   # specify PID file for management
ExecStart=/apps/nginx/sbin/nginx   # start Nginx using absolute path
ExecStop=/usr/bin/kill -s TERM $MAINPID   # stop the process
ExecReload=/apps/nginx/sbin/nginx -s reload   # reload configuration

[Install]
WantedBy=multi-user.target

Reload systemd, start Nginx, and check its status:

systemctl daemon-reload   # inform systemd of the new unit file
systemctl start nginx      # start Nginx
systemctl status nginx     # verify that Nginx is running

For further configuration, edit the Nginx configuration files under /apps/nginx/conf as needed.

Source: https://www.cnblogs.com/chenjw0608/p/17813477.html (© original author)

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.

CompilationLinuxNginxInstallation
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.