问题描述
1.后台使用X-Accel-Redirect来指定反向代理的网站:
X-Accel-Redirect: /proxy/domain.com/path/to/index.php?id=1
或者
X-Accel-Redirect: /proxy/domain.com/path/to/index?id=1
2.nginx中location配置类似如下来反向代理
location ~* ^/proxy/(.*?)/(.*){
set $proxy_host $1;
set $proxy_uri $2;
set $proxy_url http://$proxy_host/$proxy_uri$is_args$args;
proxy_pass $proxy_url;//想在这里原封不动的把后台传递的网址进行代理
}
对于第一个带php后缀的代理,此location块没有被匹配到,页面显示404。
而对于第二个没带php的,正常匹配到。
因此猜测原因在于index.php中的点号(.)号无法被匹配到。
环境背景及自己尝试过哪些方法
nginx/1.14.2
尝试的方法:
参考匹配带后缀的文件像location ~ \.php$
我也试着这样写location ~* ^/proxy/(.*?)/(.+\.php)
,但也无法被匹配的
这星号应该是匹配除换行符以外的所有字符,难以理解。
在nginx文档中看到
The matching is performed against a normalized URI, after decoding the text encoded in the “%XX” form, resolving references to relative path components “.” and “..”, and possible compression of two or more adjacent slashes into a single slash.
解析url中的".",".."?不知道是什么意思
求大佬能够指点一下,十分感谢。
自己看了下locatio的正则匹配顺序,猜测可能是因为此块上面有匹配php后缀的location,于是这块被忽略了。八成如此了,回去改改location的顺序