[英]nginx execute .php as .gif file rewrite rules
访问这个对我来说是一个很大的挑战:
mysite.com/cookie/image.php?perma=perma1
像这样;
mysite.com/cookie/perma1.gif
或者
mysite.com/cookie/image.php?perma=perma1
作为
mysite.com/cookie/perma2.gif
因此,每当我在后台请求perma1.gif or perma2.gif
时,nginx 都会运行
image.php?perma=perma1
和
image.php?perma=perma2
分别。
因此,对于您的问题,您的 nginx server.conf 的正确规则应该是:
location ~* ^/cookie/(.*)\.(gif)$ {
try_files $uri $uri/ /cookie/image.php?perma=$1;
}
这条规则意味着:
...这应该可以解决您的问题。
因此,每当我在后台请求 perma1.gif 或 perma2.gif 时,nginx 都会运行
这意味着try_files
是完全没有必要的,不仅@MatWer 的答案总是会尝试检查例如/cookie/perma1.gif
的存在,而且还会检查目录/cookie/perma1.gif/
的存在(这是两个不必要的系统stat
调用)。
最有效的是放置在server
上下文中的简单重写(在任何location
之外):
rewrite ^/cookie/(.*)\.gif$ /cookie/image.php?perma=$1 last;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.