【问题标题】:How to fix Nginx config that downloads PHP file after rewrite directives?如何修复重写指令后下载 PHP 文件的 Nginx 配置?
【发布时间】:2019-11-07 16:45:51
【问题描述】:

这是我的 nginx conf 的摘录:

location / {
    try_files $uri $uri/ /index.php$is_args$args @no-dot-php;
    autoindex on;
}

location ~ \.php$ {
    internal;
    try_files $uri =404;
    include snippets/fastcgi-php.conf;
    fastcgi_pass php_upstream;      
}

location @no-dot-php {
    rewrite ^(.*)$ /$1.php last;
}

我想使用一个无扩展的 php 指令,它工作正常。我添加了internal;,这样如果您将 .php 添加到 url,它会抛出 404,这是可行的。

如果 url 是@987654321@,它会正确显示页面。

现在这是我的问题。如果没有 url 参数,php 文件将被下载而不是被渲染。例如:@987654322@ 它将下载 'manage-tasks' php 文件。

添加一个虚拟参数可以解决问题,但这真的很奇怪。例如:@987654323@

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 术语 /index.php$is_args$args 导致问题 - 删除它。
  • @RichardSmith 谢谢!它确实解决了问题。

标签: php nginx url-rewriting


【解决方案1】:

解决方案:

术语 /index.php$is_args$args 导致了问题 - 删除它。

由理查德·史密斯提供

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-23
    相关资源
    最近更新 更多