繁体   English   中英

Nginx –重写规则疯狂

[英]Nginx – Rewrite rule madness

我正在尝试重定向如下所示的链接:

http://example.com/dev/some_project

到他们的实际位置:

http://example.com/dev/some_project/some_project.php

为了实现这一目标,我提出了以下规则集:

location / {
    try_files $uri $uri/ @folderless-php;
    index index.php index.html index.htm;
}


location @folderless-php {
    rewrite ^(.*)$ "${uri}/${basename}.php";
}

但是,由于某种原因,这只会引起内部服务器错误。

所以我尝试将其更改为:

location / {
    set $folderless "${uri}/${basename}.php";
    try_files $uri $uri/ $folderless;
    index index.php index.html index.htm;
}

这似乎可以使用curl ,但是当我在任何浏览器中尝试使用它时,都被提供下载我尝试访问的文件的机会,这令我惊讶。

是什么导致此行为? 有没有办法实现我想要做的事情?

尚未告诉Nginx如何处理PHP文件,因此您将获得下载。 您需要将fast-cgi参数设置为类似以下内容:

location ~ \.php$ {
    fastcgi_read_timeout 60000;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME /var/www/site$fastcgi_script_name;
    include         fastcgi_params;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM