Preface#
Recently, I set up a new server. Since it only has 1c1g, I don't plan to install a panel.
Then I thought about compiling and installing Nginx manually, and I can also write an article.
Prerequisites#
If it's a minimal server image, it's likely to be missing some components.
Let's do a quick installation.
sudo apt update
sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev git
Installation#
Download the Nginx source code.
wget https://nginx.org/download/nginx-1.27.3.tar.gz
tar -zxvf nginx-1.27.3.tar.gz
cd nginx-1.27.3
Download the required modules and OpenSSL.
git clone https://github.com/openresty/headers-more-nginx-module
git clone https://github.com/quictls/openssl
mv openssl-openssl-3.0.13-quic openssl
Configure the compilation options.
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_v3_module \
--with-openssl=./openssl \
--with-openssl-opt="enable-tls1_3" \
--with-cc-opt="-I/usr/local/include" \
--with-ld-opt="-L/usr/local/lib" \
--add-module=./headers-more-nginx-module
Let's get started!
make -j$(nproc)
make install
After a short wait, Nginx should be installed successfully.
Let's verify it.
root@Miao:~# nginx -V
nginx version: nginx/1.27.3
built by gcc 12.2.0 (Debian 12.2.0-14)
built with OpenSSL 3.1.7+quic 3 Sep 2024
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-http_ssl_module --with-http_v2_module --with-http_v3_module --with-openssl=./openssl --with-openssl-opt=enable-tls1_3 --with-cc-opt=-I/usr/local/include --with-ld-opt=-L/usr/local/lib --add-module=./headers-more-nginx-module
root@Miao:~#
Configure systemd#
After installation, I found that there is no default systemd service configuration.
Since that's the case, let's write one ourselves.
[Unit]
Description=Nginx - A high performance web server and reverse proxy server
Documentation=https://nginx.org/en/docs/
After=network.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Start#
systemctl enable nginx
systemctl start nginx
This completes the setup.
Let's check the status.
root@Miao:~# systemctl status nginx
● nginx.service - Nginx - A high performance web server and reverse proxy server
Loaded: loaded (/etc/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Sun 2024-12-22 16:20:27 UTC; 12s ago
Docs: https://nginx.org/en/docs/
Main PID: 36430 (nginx)
Tasks: 2 (limit: 1063)
Memory: 1.9M
CPU: 19ms
CGroup: /system.slice/nginx.service
├─36430 "nginx: master process /usr/sbin/nginx"
└─36431 "nginx: worker process"
Dec 22 16:20:27 Miao systemd[1]: Starting nginx.service - Nginx - A high performance web server and rever>
Dec 22 16:20:27 Miao nginx[36428]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Dec 22 16:20:27 Miao nginx[36428]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Dec 22 16:20:27 Miao systemd[1]: Started nginx.service - Nginx - A high performance web server and revers>
lines 1-18/18 (END)
This marks a great success.
If you found this article useful, please give it a thumbs up. Thank you!
This article is synchronized and updated to xLog by Mix Space.
The original link is https://blog.xcnya.cn/posts/maintain/127.html