前言#
最近新整了一台伺服器,由於只有 1c1g 所以不打算裝面板
然後就想到了土法編譯安裝 Nginx,順便還能水個文章
前置#
如果是鏡像及其精簡的伺服器,那麼大概率缺東西
淺裝一下
sudo apt update
sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev git
安裝#
下載 Nginx 源碼
wget https://nginx.org/download/nginx-1.27.3.tar.gz
tar -zxvf nginx-1.27.3.tar.gz
cd nginx-1.27.3
下載需要的模組和 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 --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
開跑!
make -j$(nproc)
make install
稍作等待,不出意外 Nginx 就已經安裝完成了
驗證一下
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:~#
配置 systemd#
裝完發現默認是沒有 systemd service 配置的
既然這樣那就自己寫一個
[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
啟動#
systemctl enable nginx
systemctl start nginx
這樣就完成了
看看狀態
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"
12月 22 16:20:27 Miao systemd[1]: Starting nginx.service - Nginx - A high performance web server and rever>
12月 22 16:20:27 Miao nginx[36428]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
12月 22 16:20:27 Miao nginx[36428]: nginx: configuration file /etc/nginx/nginx.conf test is successful
12月 22 16:20:27 Miao systemd[1]: Started nginx.service - Nginx - A high performance web server and revers>
lines 1-18/18 (END)
這樣就算是大功告成了
如果文章對你有用,還請點個讚,謝謝喵
此文由 Mix Space 同步更新至 xLog
原始鏈接為 https://blog.xcnya.cn/posts/maintain/127.html