nginx平滑升级+location案例 - 教程
nginx平滑升级+location案例
一、平滑升级
1、部署nginx(略)
2、获取之前安装的nginx编译参数
[root@stw ~]# nginx -V
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
3、下载新模块(echo-nginx-module-master.zip)
[root@stw ~]# rz -E
rz waiting to receive.
[root@stw ~]# ls
anaconda-ks.cfg Downloads Music Public
Desktop echo-nginx-module-master.zip nginx-1.24.0.tar.gz Templates
Documents initial-setup-ks.cfg Pictures Videos
4、重新编译软件
(1)解压新的模块包
[root@stw ~]# unzip echo-nginx-module-master.zip
[root@stw ~]# ls
anaconda-ks.cfg echo-nginx-module-master nginx-1.24.0.tar.gz Videos
Desktop echo-nginx-module-master.zip Pictures
Documents initial-setup-ks.cfg Public
Downloads Music Templates
(2)再次解压nginx源码包(解压到当前目录不指定目录)
[root@stw ~]# tar -zxf nginx-1.24.0.tar.gz
[root@stw ~]# ls
anaconda-ks.cfg echo-nginx-module-master nginx-1.24.0 Templates
Desktop echo-nginx-module-master.zip nginx-1.24.0.tar.gz Videos
Documents initial-setup-ks.cfg Pictures
Downloads Music Public
(3)添加新的模块进行编译安装(在原来编译安装的基础上加上–add-module=/root/echo-nginx-module-master)
[root@stw nginx-1.24.0]# nginx -V
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
[root@stw nginx-1.24.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=/root/echo-nginx-module-master
(4)查看objs目录下没有nginx程序
[root@stw nginx-1.24.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[root@stw nginx-1.24.0]# ls objs/
addon Makefile ngx_auto_headers.h src
autoconf.err ngx_auto_config.h ngx_modules.c
(5)使用make编译,编译完成之后再次查看objs目录下有nginx程序
[root@stw nginx-1.24.0]# make
[root@stw nginx-1.24.0]# ls objs/
addon Makefile nginx.8 ngx_auto_headers.h ngx_modules.o
autoconf.err nginx ngx_auto_config.h ngx_modules.c src
5、备份源程序并停止、覆盖、启动服务
(1)确保没有启动nginx(不能查看到80端口)
[root@stw nginx-1.24.0]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:6000 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::6000 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
(2)先查看升级前和升级后的版本区别,主要看编译参数
升级前:
[root@stw nginx-1.24.0]# nginx -V
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
升级后:
[root@stw nginx-1.24.0]# objs/nginx -V
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=/root/echo-nginx-module-master
(3)停止、备份、覆盖、启动程序(这里我已经停了服务)
备份
[root@stw nginx-1.24.0]# cd /usr/local/nginx/sbin
[root@stw sbin]# ls
nginx
[root@stw sbin]# cp /usr/local/nginx/sbin/nginx /opt/
覆盖
[root@stw sbin]# cd -
/root/nginx-1.24.0
[root@stw nginx-1.24.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[root@stw nginx-1.24.0]# cp objs/nginx /usr/local/nginx/sbin/
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y
[root@stw nginx-1.24.0]# nginx -V
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=/root/echo-nginx-module-master
启动服务
[root@stw nginx-1.24.0]# nginx
[root@stw nginx-1.24.0]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:6000 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::6000 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
6、测试–引用echo模块
[root@stw ~]# vim /usr/local/nginx/conf/nginx.conf
[root@stw ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@stw ~]# nginx -s reload
使用浏览器访问,发现浏览器无法支持echo模块,会当成文件进行下载
在新的主机中使用命令进行访问
[root@stw2 ~]# curl http://192.168.100.10
yyqx
二、location案例
Nginx 修饰符
修饰符 | 名称/类型 | 核心功能描述 |
---|---|---|
= | 精确匹配 | 仅当请求的 URI 与指定模式完全一致时才匹配,不允许任何多余字符或差异 |
~ | 正则表达式匹配(区分大小写) | 使用正则表达式对 URI 进行匹配,且严格区分字符的大小写(如 A 与 a 视为不同) |
~* | 正则表达式匹配(不区分大小写) | 使用正则表达式对 URI 进行匹配,不区分字符的大小写(如 A 与 a 视为相同) |
^~ | 前缀匹配(终止搜索) | 匹配以指定模式为前缀的 URI,且一旦匹配成功,立即停止后续其他模式(包括正则)的搜索 |
@ | 命名 location 标记 | 用于定义内部可访问的命名 location 区段,客户端无法直接通过 URI 访问 |
1、没有修饰符表示必须以指定模式开始
node1:
[root@stw ~]# vim /usr/local/nginx/conf/nginx.conf
[root@stw ~]# nginx -s reload
node2:
[root@stw2 ~]# curl http://192.168.100.10
yyqx
[root@stw2 ~]# curl http://192.168.100.10/abc
yyqx
[root@stw2 ~]# curl http://192.168.100.10/abc/
yyqx
[root@stw2 ~]# curl http://192.168.100.10/abc/abcs
yyqx
[root@stw2 ~]# curl http://192.168.100.10/abc/abcsedsee
yyqx
[root@stw2 ~]# curl http://192.168.100.10/aaabc/abcsedsee
<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>nginx/1.24.0</center></body></html>[root@stw2 ~]# curl http://192.168.100.10/abcaa/abcsedseeyyqx
2、用 “ = ” 精准匹配(只能用/abc访问,写的是什么就用什么)
node1:
[root@stw ~]# vim /usr/local/nginx/conf/nginx.conf
[root@stw ~]# nginx -s reload
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
yyqx
[root@stw2 ~]# curl http://192.168.100.10/abcsdf
<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>nginx/1.24.0</center></body></html>
3、~:表示指定的正则表达式要区分大小写
node1:这里是匹配以/abc结尾的(且区分大小写)
[root@stw ~]# vim /usr/local/nginx/conf/nginx.conf
[root@stw ~]# nginx -s reload
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
yyqx
[root@stw2 ~]# curl http://192.168.100.10/abc/
<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>nginx/1.24.0</center></body></html>[root@stw2 ~]# curl http://192.168.100.10/abcasd<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>nginx/1.24.0</center></body></html>[root@stw2 ~]# curl http://192.168.100.10/axdsabc<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>nginx/1.24.0</center></body></html>[root@stw2 ~]# curl http://192.168.100.10/axds/abcyyqx[root@stw2 ~]# curl http://192.168.100.10/axds/Abc<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>nginx/1.24.0</center></body></html>
4、~*:表示指定的正则表达式不区分大小写
node1:
[root@stw ~]# vim /usr/local/nginx/conf/nginx.conf
[root@stw ~]# nginx -s reload
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
yyqx
[root@stw2 ~]# curl http://192.168.100.10/Abc
yyqx
[root@stw2 ~]# curl http://192.168.100.10/ABC
yyqx
5、^~ 前缀匹配,类似于无修饰符的行为,也是以指定模块开始,不同的是,如果模式匹配,那么就停止搜索其他模式了,不支持正则表达式
node1:
[root@stw ~]# vim /usr/local/nginx/conf/nginx.conf
[root@stw ~]# nginx -s reload
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
yyqx
[root@stw2 ~]# curl http://192.168.100.10/abcaxs
yyqx
[root@stw2 ~]# curl http://192.168.100.10/abc/
yyqx
[root@stw2 ~]# curl http://192.168.100.10/abc/wasd
yyqx
[root@stw2 ~]# curl http://192.168.100.10/asabc/wasd
<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>nginx/1.24.0</center></body></html>
6、当“=”和“~”同时存在时,此时时 = 优先于 ~
node1:
[root@stw ~]# vim /usr/local/nginx/conf/nginx.conf
[root@stw ~]# nginx -s reload
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
lh
6、查找顺序和优先级:由高到低
1、带有 =
的精确匹配优先
2、正则表达式按照他们在配置文件中定义的顺序(比如定义两个精准匹配,那么按照顺序匹配)
3、带有 ^~
修饰符的,开头匹配
4、带有~
或者~*
修饰符的,如果正则表达式与URI匹配
5、没有修饰符的精确匹配
举例说明
node1:
[root@stw ~]# vim /usr/local/nginx/conf/nginx.conf
[root@stw ~]# nginx -s reload
location = /abc {
echo "=";
}
location ^~ /abc {
echo "^~";
}
location ~ /abc {
echo "~";
}
location ~* /abc {
echo "~*";
}
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
=
//说明精准匹配优先级最高:=
node1:
location ^~ /abc {
echo "^~";
}
location ~ /abc {
echo "~";
}
location ~* /abc {
echo "~*";
}
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
^~
//前缀匹配优先级第二:^~
node1:
location ~ /abc {
echo "~";
}
location ~* /abc {
echo "~*";
}
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
~
//正则匹配区分大小写优先级第三:~
node1:
location ~* /abc {
echo "~*";
}
location /abc {
echo "123";
}
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
~*
//正则匹配不区分大小写优先级第四:~*
//直接接路径优先级最后
node1:
location ~* /abc {
echo "~*";
}
location /abc {
echo "123";
}
node2:
[root@stw2 ~]# curl http://192.168.100.10/abc
~*
//正则匹配不区分大小写优先级第四:~*
//直接接路径优先级最后
location = 路径
location ^~ 路径
location ~ 正则
location ~* 正则
location 路径
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/918237.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!相关文章
深入解析:装备制造企业支撑智能制造的全生命周期数据治理实践
pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …
确定网站开发团队湖南网页
状态图(Statechart Diagram)是描述一个实体基于事件反应的动态行为,显示了该实体如何根据当前所处的状态对不同的事件做出反应。通常我们创建一个UML状态图是为了以下的研究目的:研究类、角色、子系统、或组件的复杂行为。
柳州市网站建设免费软件下载中心
随着科技的飞速发展,媒体内容已成为我们日常生活中不可或缺的一部分。为了满足用户对高质量视频内容不断增长的需求,Media Encoder 2024应运而生,它凭借卓越的技术和创新的特性,重塑了媒体编码的未来。
Media Encoder 2024软件获…
贪玩传奇手游官方网站成品网站5668入口的功能介绍
“”和“equals”的区别 Java中“”和“equals”的区别在于,它们比较的内容不同。""比较的是对象的引用是否相等,而equals比较的是对象的值是否相等。
具体来说,以下是两个操作符之间的区别:
“”比较的是对象的引用&…
学生如何建设网站北京海淀区公司
文章目录1. 题目2. 解题1. 题目
给你一个整数 num 。重排 num 中的各位数字,使其值 最小化 且不含 任何 前导零。
返回不含前导零且值最小的重排数字。
注意,重排各位数字后,num 的符号不会改变。
示例 1:
输入:nu…
深入解析:P4779 【模板】单源最短路径(标准版)
pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …
US$36 35160WT Adapter for CG Pro 9S12 Programmer
35160WT Adapter for CG Pro 9S12 Programmer35160WT Adapter Features: For the 35160T chip design that cannot be erased, it can directly repair the original vehicle red dot and directly use the original c…
[更新完毕]2025华为杯B题数学建模研赛B题研究生数学建模思路代码文章成品:无线通信系统链路速率建模 - 指南
[更新完毕]2025华为杯B题数学建模研赛B题研究生数学建模思路代码文章成品:无线通信系统链路速率建模 - 指南2025-09-26 12:13
tlnshuju
阅读(0)
评论(0) 收藏
举报pre { white-space: pre !important; word-wrap: …
西安北郊网站开发wordpress 主题 企业
线程启动原理线程中断机制多线程实现方式FutureTask实现原理线程池之ThreadPoolExecutor概述线程池之ThreadPoolExecutor使用线程池之ThreadPoolExecutor状态控制线程池之ThreadPoolExecutor执行原理线程池之ScheduledThreadPoolExecutor概述线程池的优雅关闭实践
转载&#x…
适合大学生做的兼职网站有哪些网页一键建站
敏捷开发模式已经逐渐被主流的软件研发团队所接受,其中Scrum是最具代表性的敏捷方法之一。Scrum框架中有三个核心角色:Product Owner(PO)、Scrum Master(SM)和Development Team(DT)。…
模式组合应用-享元模式 - 详解
模式组合应用-享元模式 - 详解pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco"…
【Spring Boot】自定义starter
Spring Boot 自定义Starter
为什么要自定义Starter
Spring Boot Starter 是一种简化依赖管理和自动配置的机制。下面详细介绍如何创建自定义 Starter。
Starter 的基本概念
命名规范
官方 Starter: spring-boot-star…
redis-bitMap类型基本命令
redis-bitMap类型基本命令BitMap是reids2.2.0版本中引入的一种新的数据类型。该数据类型本质上就是一个只包含0和1的二进制字符串。
它的所有命令都是对这个字符串二进制位的操作。字符串中的每个字符对应的索引称为of…
PrintNightmare漏洞仍未终结:深入解析PnP配置绕过与防护方案
本文深入分析了PrintNightmare漏洞的最新演变,详细介绍了攻击者如何通过DNS欺骗绕过Point and Print安全策略,并评估了UNC路径加固、RPC over SMB等多种防护方案的有效性。文章通过实际测试展示了防护措施的局限性,…
Go 1.26 内置函数 new 新特性
目前golang 1.26的各种新特性还在开发中,不过其中一个在开发完成之前就已经被官方拿到台面上进行宣传了——内置函数new功能扩展。
每个新特性其实都有它的背景故事,没有需求的驱动也就不会有新特性的诞生。所以在介…
基于SpringBoot及PostgreSQL的国家减肥食谱管理项目(上):区域与省份安装搭建
基于SpringBoot及PostgreSQL的国家减肥食谱管理项目(上):区域与省份安装搭建pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-f…
基于BP神经网络的激光焊接数据预测
基于BP神经网络的激光焊接数据预测的系统化方法,结合核心原理、实现步骤及工程优化策略,适用于焊接质量控制和工艺参数优化:
一、BP神经网络原理与激光焊接预测适配性核心机制
BP神经网络通过误差反向传播调整权重,…
重要公式 - Emi
重要的三角函数公式
\[sin\alpha cos\beta=\frac{sin(\alpha+\beta)+sin(\alpha-\beta)}{2}
\]\[cos\alpha cos\beta=\frac{cos(\alpha+\beta)+cos(\alpha-\beta)}{2}
\]\[sin\alpha sin\beta=-\frac{cos(\alpha+\beta…
Pandawiki:企业知识管理的全能管家
Pandawiki:企业知识管理的全能管家在当今这个信息爆炸的时代,每个企业都面临着一个共同的挑战:如何有效地管理和利用内部积累的海量知识资产?从产品文档到技术规范,从客户问答到项目经验,这些宝贵的信息往往散落…
珠宝网站建设做网站项目流程图模板
Spring的开发要点总结 文章目录 【JavaEE】Spring的开发要点总结(1)1. DI 和 DL1.1 DI 依赖注入1.2 DL 依赖查询1.3 DI 与 DL的区别1.4 IoC 与 DI/DL 的区别 2. Spring项目的创建2.1 创建Maven项目2.2 设置国内源2.2.1 勾选2.2.2 删除本地jar包2.2.3 re…