Build from Source (Recommended Method)
Start by getting required tools to build from source
apt install build-essential
Install required packages for common modules
apt install libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
Head to the Download page on NGINX website
Download the latest mainline release by running
wget https://nginx.org/download/nginx-1.21.5.tar.gz
Extract zipped file and change into it
tar nginx-1.21.5.tar.gz
cd nginx-1.21.5
To build NGINX from source with modules. In the extracted file 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 --with-http_v2_module
Then
make
Then, to install with modules
make install
To check installed version and packages
nginx -V
Β
Creating System Service
To make NGINX a system service, start by creating a service file and opening it
touch /lib/systemd/system/nginx.service
nano /lib/systemd/system/nginx.service
Populate fileβs content with
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/bin/nginx -t
ExecStart=/usr/bin/nginx
ExecReload=/usr/bin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Now NGINX service commands can be ran using
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx
Β
Β
Loading Comments...