十二 nginx中location重写和匹配规则

2024-06-11 22:36

本文主要是介绍十二 nginx中location重写和匹配规则,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

十二 location匹配规则 
= ^~ ~ ~*  !~ !~* /a   / @
@内部服务跳转

十三 nginx地址重写rewrite
if rewrite set return 

13.1 if 应用环境 
server location

-x  文件是否可执行 
$args  
$document_rot
$host
$limit_rate 
$remote_addr 
$server_name 
$document_uri  

if (coduction) {
... 
 }

13.2 rewrite  flag  
last     
break     本条匹配完成后 终止匹配
redirect     302  临时重定向 
permanent   301  永久重定向 

80 http
443 https  

案例1
修改前:http://www.dadishu.com/a/index.html 
修改后:http://www.dadishu.com/b/index.html
server   {
      listen 80;
      server_name www.dadishu.com;
location / {
       root   /data/wwwroot 
       index index.html
      }
location /a {
    root /html; 
    index   index.html;
   rewrite  .* /b/2.html permanent;
}
location /b {
    root /html; 
    index  index.html;
}
}

案例2 
http://www.testpm.com/2019/a/index.html 
http://www.testpm.com/2018/a/index.html
location /2019/a {
    root     /html;
    index  index.html;
    rewrite ^/2019/(.*)$ /2018/$1  permanent; 
}
location /2018/a {
    root /html;
    index  index.html;
}

案例三 核心
http://www.qf.com/a/1.html   http://jd.com 
location /a  {
    root /html;
    if ($host ~* www.qf.com) {
    rewrite .* http//jd.com permanent;
    }
}

案例四 
http://www.qf.com/a/1.html  http://jd.com/a/1.html 

location /a {
    root /html;
    if ($host ~* qf.com){
rewrite .* http://jd.com$request_uri permanent;
    }
}

案例五 
修改前:http//www.tianyun.com/login/tianyun.html 
修改后:http://www.tianyun.com/reg/login.html?user=tianyun
location /login {
    root /usr/share/nginx/html;
    rewrite ^/login/(.*)\.html$ http://$host/reg/login.html?user=$1;

location /reg {
root /usr/share/nginx/html;
index login.html;    
}

13.3  set指令 
应用环境 server location if 

13.4 return  
server location if 


 

这篇关于十二 nginx中location重写和匹配规则的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1052441

相关文章

设置Nginx缓存策略

详细信息 Nginx服务器的缓存策略设置方法有两种:add_header或者expires。 1. add_header 1)语法:add_header name value。 2)默认值:none。 3)使用范围:http、server、location。 配置示例如下: add_header cache-control "max-age=86400";#设置缓存时间为1天。add

XMG 重写- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event方法

//重写这个方法,来完成一些指定的事件。比如说按钮被遮到下面了,但是我想让点击到这块区域的时候让按钮去相应点击 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {     // 当前坐标系上的点转换到按钮上的点     CGPoint btnP = [self convertPoint:point toVi

odoo中的补货规则

在 Odoo 17 ERP 中,补货规则(Reordering Rules)是一个有效的库存补充工具。企业可以最大限度地减少缺货,并优化库存周转。补充产品以保持适当库存水平的过程被称为补货。补货规则被认为是企业达到更高水平的关键因素之一。 设置补货规则 1.选择产品 要在Odoo 17中设置补货规则,请依次进入库存 -> 产品 -> 产品。 2.选择一个可存储的产品来配置补货规则。

编译测试后出现“发现不明确的匹配”错误

原文链接:http://blog.163.com/zhaoyanping_1125/blog/static/201329153201204218533/ 错误提示: 【“/”应用程序中的服务器错误。  分析器错误 说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。  分析器错误信息: 发现不明确的匹配。】   这个问题发生原因一般情况是

Docker Compose--安装Nginx--方法/实例

原文网址:Docker Compose--安装Nginx--方法/实例_IT利刃出鞘的博客-CSDN博客 简介 说明 本文介绍Docker Compose如何安装Nginx。 目录结构 ├── config│   ├── cert│   │   ├── xxx_bundle.pem│   │   └── xxx.key│   ├── conf.d│   └── nginx.co

nginx 8051#0: *4 recv() failed (104: Connection reset by peer) while reading response header from u

环境    php7   nginx1.8.0    nginx   报错  500  GATWAY网关错误 2017/08/28 10:45:42 [error] 7975#0: *333 recv() failed (104: Connection reset by peer) while reading response header from upstream, clien

nginx 504 Gateway Time-out

环境:PHP7.1,NGINX,Mysql 问题描述: 本地写了一个需要执行比较长时间的脚本,放到了php-fpm里面跑。用一个链接调用起这个脚本。发现第一次调用的时候,需要等比较久的时间,但是如果在执行期间再次请求这个链接。第二个请求的链接会返回504。甚至,直接在脚本最开始的地方中断都还是报 504. 但是如果请求其他链接,可以正常请求。 nginx 返回码、、 504 Gateway

linux匹配Nginx日志,某个字符开头和结尾的字符串

匹配 os=1 开头, &ip结尾的字符串 cat 2018-06-07.log | egrep -o ‘os=1.*.&ip’ 存入日志。然后使用submit 前面和后面的值去掉,剩下就是需要的字符串。 cat 2018-06-07.log | egrep -o ‘os=1.*.&ip’ >log.log

nginx问题记录以及解决方法

问题描述: 打开多个nginx.exe 结果在任务管理器中不能结束该进程 解决办法: 以管理员的身份运行cmd 1、查看所有nginx.exe 进程 tasklist /fi "imagename eq nginx.exe" 2、结束这些进程 taskkill /fi "imagename eq nginx.exe" /f 问题描述: 配置前端项目路径然后就直接看本地项目路径的属

Nginx基础概念和常用操作

文章目录 1. 安装、启动、连接2. 快速尝试部署网站3. 配置文件1. nginx.conf全局配置事件模块HTTP 模块性能优化建议 2. default.conf`server` 块基本设置日志设置根路径设置 4. 反向代理1. 模拟3个Web2. 链接 5. 负载均衡1. 加权轮询,Weighted Round Robin2. 最少连接,Least Connections3. I