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 --------------------------------------------