【问题标题】:Nginx returns a 404 for URLs like index.php/some/pathNginx 为 index.php/some/path 之类的 URL 返回 404
【发布时间】:2014-10-15 05:18:26
【问题描述】:

当我查询一个在脚本名称后附加“路径信息”的 URL 时,Nginx 返回 404,例如http://example.com/index.php/hello.

这是我的配置:

server {
    listen  80;
    root    @PROJECT_ROOT@/;
    index   index.php index.html;

    location ~ \.php$ {
        fastcgi_pass    unix:@PHP_FPM_SOCK@;
        include fastcgi_params;
        fastcgi_read_timeout 300s;
    }
}

我不明白为什么\.php$ 与那个 URL 不匹配,我尝试搜索类似的问题但找不到任何有用的东西。

【问题讨论】:

标签: php nginx


【解决方案1】:

使用

位置~^.+.php {

fastcgi_split_path_info ^(.+?.php)(/.*)$;

匹配 uri 中的 .php 拆分参数

【讨论】:

  • 匹配范围太广——任何字符后面跟“php”。您需要在文字句点之前使用反斜杠。
【解决方案2】:

这对我有用:

location ~ \.php {
    # Split the path appropriately
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;

    # Work around annoying nginx "feature" (https://trac.nginx.org/nginx/ticket/321)
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;

    # Make sure the script exists.
    try_files $fastcgi_script_name =404;

    # Configure everything else.  This part may be different for you.
    fastcgi_pass localhost:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 2020-08-27
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多