抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

首先安装编译工具及相关依赖库

1
sudo apt install make gcc libpcre3 libpcre3-dev zlib1g-dev libssl-dev

下载最新nginx源代码编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
wget https://nginx.org/download/nginx-1.26.2.tar.gz
tar -zxvf nginx-1.26.2.tar.gz
mv nginx-1.26.2 nginx
cd nginx
./configure --with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream=dynamic \
--with-http_ssl_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_v3_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_sub_module
make
make install

配置服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
nano /etc/systemd/system/nginx.service
# 添加以下内容
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

重新加载服务

1
sudo systemctl daemon-reload

配置开机自启

1
sudo systemctl enable nginx

Docker安装方式(自定义文件挂载路径)

Docker安装:curl -fsSL https://get.docker.com | bash -s docker

1
2
3
4
5
6
docker run --name nginx \
-itd --network=host \
-p 80:80 -p 443:443 \
-v /root/nginx-data/conf:/etc/nginx/conf.d \
-v /root/nginx-data/cert:/etc/nginx/cert \
-d --restart=always nginx