当前位置: 首页 > news >正文

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


 

http://www.lryc.cn/news/369530.html

相关文章:

  • python的视频处理FFmpeg库使用
  • 接口测试时, 数据Mock为何如此重要?
  • 未授权与绕过漏洞
  • 云原生周刊:Kubernetes 十周年 | 2024.6.11
  • ClickHouse内幕(1)数据存储与过滤机制
  • 1.Mongodb 介绍及部署
  • Java 技巧:如何获取字符串中最后一个英文逗号后面的内容
  • 玩转微服务-GateWay
  • Amortized bootstrapping via Automorphisms
  • 【人工智能】ChatGPT基本工作原理
  • The First项目报告:Stargate Finance重塑跨链金融的未来
  • Python魔法之旅-魔法方法(22)
  • 公司面试题总结(三)
  • PLSQL 报错 could not locate oci.dll
  • 【方案+源码】智慧园区建设方案
  • Java操作数据库 —— JDBC ① 基础篇
  • webpack和vite区别
  • FL Studio21永久免费破解中文版下载,让我这个音乐制作爱好者如获至宝!
  • vue3 监听器,组合式API的watch用法
  • 苹果WWDC开幕发布AI大模型,股价却跌近2%
  • C++ 11 【可变参数模板】【lambda】
  • c 宏应用举例
  • 微信公众号(公众平台) 和 微信开放平台的scope的差异
  • 基于pytorch实现的DenseUnet医学图像分割(腹部多脏器)
  • 富格林:正规策划实现安全做单
  • 02. 异常捕捉和处理
  • Oracle和mysql中插入时间字段
  • 注册小程序
  • 【YOLOv8改进[CONV]】使用MSBlock二次创新C2f模块实现轻量化 + 含全部代码和详细修改方式 + 手撕结构图 + 轻量化 + 涨点
  • three.js使用环境贴图或者加载hdr图