nginx rewrite 指令

来源:互联网 发布:小米note 顶配版我知乎 编辑:程序博客网 时间:2024/05/20 02:27

1 读取报文头部

2 server重新rewrite

3 location匹配(静态二叉树查找, 只匹配一个最接近的执行)

4 location重新rewrite

5 权限处理

6 内容处理

9 打印日志


 rewrite指令是 运行时指令 按照配置文件中顺序执行


break 会终止执行当前虚拟机server中重现指令rewrite

last 会重新执行 server rewrite指令 -location匹配 以及location中的 rewrite指令

location中 的rewrite运行指令 先于其他例如 fasctcgi_pass运行指令执行

location 中的rewrite + last 则直接立刻重新执行 2 3 4 流程 (不会执行location中其他的运行指令例如fastcgi_pass)

location 中rewrite+ break 则会终止本location其他rewrite指令执行 ,仍然会运行本location中(之前或者之后)其他运行指令 例如 fastcgi_pass 或者proxy_pass 指令 (proxoy_pass指令会使用rewrite重写后的uri请q求后端地址可以打后端access_log, 

例如 

rewrite ^/trade/(.*)$ /visa/h5/index?_url=$1 break;          

rewrite ^(.*)$ /public/index.php?_url=$1 last;

proxy_pass http://127.0.0.1:8125/visa/h5/index?a=pz;


在prxoy_pass目标nginx会收到 /visa/h5/index 和 public/index.php 请求(access_log和SERVER['request_uri']取值)

其中第二个 public/index.php 可能在 nginx木有配置lcoation 静态匹配  因此走默认的location / {} 处理中(因此木有程序日志 只要access_log)

注意proxy_pass 和 fastcgi_pass指令只能出现在location中


rewrite指令默认 pernannent

rewriete permanent  表示直接返回301 + 个前端重定向到 当前域名下的新路径


0 0
原创粉丝点击