以下是详细的编译安装 Nginx 1.16.0 的步骤:
sudo yum install -y gcc gcc-c++ make automake pcre pcre-devel zlib zlib-devel openssl openssl-devel
sudo groupadd www
sudo useradd -g www www -s /sbin/nologin
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-threads \
--with-stream
make && sudo make install
sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
创建 /usr/lib/systemd/system/nginx.service
文件:
sudo vi /usr/lib/systemd/system/nginx.service
内容如下:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start nginx
sudo systemctl enable nginx
nginx -v
应该显示:nginx version: nginx/1.16.0
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
如果需要添加更多模块,可以在 configure 步骤中添加相应的选项,例如:
--with-http_v2_module \
--with-http_sub_module \
--with-stream_ssl_module
编译完成后,可以通过 nginx -V
查看已安装的模块列表。