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


 

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值