- 安装编译所需的依赖包:
sudo yum install -y gcc-c pcre-devel zlib-devel openssl-devel wget
- 下载 Nginx 1.20.2:
cd /opt
sudo wget http://nginx.org/download/nginx-1.20.2.tar.gz
sudo tar -zxvf nginx-1.20.2.tar.gz
cd nginx-1.20.2
- 配置编译选项:
./configure --user=root --group=root --prefix=/data/app/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-pcre --with-stream
安装多模块
代码语言:javascript复制./configure --prefix=/data/nginx --pid-path=/data/nginx/run/nginx.pid --user=root --group=root --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
- 编译并安装 Nginx:
sudo make
sudo make install
- 创建 Nginx 系统服务单元文件:
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The Nginx HTTP and reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/data/nginx/run/nginx.pid
ExecStartPre=/data/nginx/sbin/nginx -t
ExecStart=/data/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存并退出。
- 重新加载 systemctl 守护进程:
sudo systemctl daemon-reload
- 启动并设置 Nginx 在开机时自动启动:
sudo systemctl start nginx
sudo systemctl enable nginx
- 检查 Nginx 版本和运行状态:
nginx -v
sudo systemctl status nginx