CentOS 安装 nginx-1.19.4 与原版本共存
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 --------------------------------------------
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术