Nginx Rewrite和FastCGI - Php文件下载

时间:2015-06-17 13:44:34

标签: .htaccess mod-rewrite nginx winginx

我已将此指令块添加到我的Nginx安装

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    # With php5-cgi alone:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    # With php5-fpm:
    include fastcgi.conf;
    fastcgi_index index.php;
}

如果我联系http://myserverip/script.php,一切都会好起来的。 我需要使用重写引擎来重写一些URL,在这个指令块之后我添加了许多其他的这样的块:

location = /sentmessages {
    rewrite ^(.*)$ /sent_messages.php break;
}

(我已经使用winginx转换器来实现.htaccess规则)

如果我联系http://myserverip/sentmessages重写顺利,但PHP脚本下载而不是传递给FastCGI。 我不知道如何解决这个问题(试图改变指令的顺序但没有成功。)

如何解决?感谢。

1 个答案:

答案 0 :(得分:0)

搜索Stackoverflow后,解决方案是使用重写规则末尾的“last”。

location = /sentmessages {
    rewrite ^(.*)$ /sent_messages.php last;
}