【问题标题】:Nginx Rewrite and FastCGI - Php files get downloadedNginx Rewrite 和 FastCGI - 下载 PHP 文件
【发布时间】:2015-09-02 19:12:05
【问题描述】:

我已将这组指令添加到我的 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。 我不知道如何解决这个问题(试图更改指令的顺序但没有成功。)

如何解决?谢谢。

【问题讨论】:

  • 删除 break 并阅读文档

标签: .htaccess mod-rewrite nginx winginx


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多