先来点背景。我在nginx配置中有一些无扩展名的文件,这些文件指向php文件,例如:
/galleries/22年1月17日致电/galleries.php?mypath=$mypath&args
库位置try_files还会检查是否存在静态版本。多年来,这在我以前的CentOS服务器上一直运行良好,但我正在迁移到Ubuntu服务器,突然间,如果有人调用galleries/,我会收到一个502坏网关错误。没有尾部斜杠的调用/库可以正常工作。
首先,这里是位置:
location ~ ^/galleries(?P<mypath>/.*$|$) {
error_log /var/log/nginx/galerrors.log debug;
try_files /pixcache$request_uri/index.html /galleries.php?mypath=$mypath&$args;
fastcgi_pass 127.0.0.1:9000;
}
如果有人打电话给galleries/51/646/31,调试日志显示:
trying to use file: "/pixcache/galleries/51/646/31/index.html"
"/usr/share/nginx/html/pixcache/galleries/51/646/31/index.html"
如果没有找到静态版本,调试显示:
trying to use file: "/galleries.php?mypath=/51/646/31&"
"/usr/share/nginx/html/galleries.php?mypath=/51/646/31&"
一切都很好。然而,如果有人试图用galleries/调用主页,我们会得到这个:
trying to use file: "/pixcache/galleries//index.html"
"/usr/share/nginx/html/pixcache/galleries//index.html"
trying to use file: "/galleries.php?mypath=/&"
"/usr/share/nginx/html/galleries.php?mypath=/&"
请注意,静态文件检查中的双斜杠"//"和动态gall正在抛出坏的网关。旧服务器在这个位置运行了好几年,所以我在这里真的很头疼。我已经盯着它看了好几个小时了。我不太懂正则表达式,但这可能与此有关吗?
对于双斜杠问题,您可以激活指令
merge_slashes
有关如何进行的更多信息,请访问此处