要升级 CentOS 上的 Nginx 版本,你可以按照以下步骤操作:
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
sudo cp -r /usr/share/nginx/html /usr/share/nginx/html.backup
sudo yum remove nginx
sudo yum install epel-release
sudo yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
wget
命令下载:wget http://nginx.org/download/nginx-1.xx.x.tar.gz
将 1.xx.x
替换为你想安装的 Nginx 版本。
tar -zxvf nginx-1.xx.x.tar.gz
cd nginx-1.xx.x
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v3_module
make
sudo make install
sudo vi /etc/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/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start nginx
sudo systemctl enable nginx
nginx -V
现在,你已经成功升级了 CentOS 上的 Nginx 版本。请确保测试你的网站以确保一切正常运行。