前言
最近新整了一台服务器,由于只有 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 就已经安装完成了
验证一下
CodeBlock Loading...
配置 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
启动
CodeBlock Loading...
这样就完成了
看看状态
CodeBlock Loading...
这样就算是大功告成了
如果文章对你有用,还请点个赞,谢谢喵