1、下載nginx
http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.19.4.tar.gz
2、解壓,進入目錄
tar -zxvf nginx-1.19.4.tar.gz
cd nginx-1.19.4
3、修改nginx http header server顯示
vim src/http/ngx_http_header_filter_module.c
找到
static u_char ngx_http_server_string[] = "Server: nginx" CRLF; static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;
修改為
static u_char ngx_http_server_string[] = "Server: XXX" CRLF; static u_char ngx_http_server_full_string[] = "Server: XXX" CRLF; static u_char ngx_http_server_build_string[] = "Server: XXX" CRLF;
4、編譯安裝到/usr/local/nginx119
./configure --prefix=/usr/local/nginx119 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream --with-http_v2_module
報錯:./configure: error: the HTTP rewrite module requires the PCRE library.
解決:yum -y install pcre-devel openssl openssl-devel
再次 ./configure --prefix=/usr/local/nginx119 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream --with-http_v2_module
通過
make -j
make install
5、查看安裝是否成功
cd /usr/local/nginx119/sbin
./nginx
6、舊版本配置文件遷移
7、配置新的nginx服務,以nginx119命名
nginx.conf 設置
pid /var/run/nginx119.pid;
到nginx目錄下新生成nginx可執行程序軟連接nginx119
ln -s nginx nginx119
生成新的服務腳本
------------------------------------centos 6.x start ------------------------------------------------------------
cd /etc/init.d/
cp nginx nginx119
vim nginx119
修改路徑相關內容如下:
nginx="/usr/local/nginx119/sbin/nginx119" prog="$(basename $nginx)" sysconfig="/etc/sysconfig/${prog}" lockfile="/var/lock/subsys/nginx119" pidfile="/var/run/${prog}.pid" NGINX_CONF_FILE="/usr/local/nginx119/conf/nginx.conf"
創建sysconfig文件
cd /etc/sysconfig/
cp nginx nginx119
vim nginx119
修改原有內容為:
NGINX_CONF_FILE="/usr/local/nginx119/conf/nginx.conf"
service nginx119 start
service nginx119 status
service nginx119 stop
測試都沒問題
------------------------------------------------centos 6.x end --------------------------------------------
-----------------------------------------------centos 7.x start --------------------------------------------
cd /usr/lib/systemd/system
cp nginx.service nginx119.service
vim nginx119.service
[Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/nginx119.pid # Nginx will fail to start if /run/nginx.pid already exists but has the wrong # SELinux context. This might happen when running `nginx -t` from the cmdline. # https://bugzilla.redhat.com/show_bug.cgi?id=1268621 ExecStartPre=/usr/bin/rm -f /var/run/nginx119.pid ExecStartPre=/usr/local/nginx119/sbin/nginx -t ExecStart=/usr/local/nginx119/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target
systemctl start nginx119.service
systemctl status nginx119.service
systemctl stop nginx119.service
測試都沒問題
-----------------------------------------------centos 7.x end-----------------------------------------------
7、配置開機啟動
------------------------------------------------centos 6.x start --------------------------------------------
chkconfig nginx119 on
chkconfig nginx off # 關閉原來nginx自動啟
chkconfig # 查看是否開機啟動成功
-----------------------------------------------centos 6.x end --------------------------------------------
------------------------------------------------centos 7.x start --------------------------------------------
systemctl enable nginx119.service
systemctl disable nginx.service # 關閉原來nginx自動啟
systemctl status nginx119.service # 查看是否開機啟動成功
-----------------------------------------------centos 7.x end --------------------------------------------
