首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对于index.php/some/path这样的URL,Nginx返回404

问对于index.php/some/path这样的URL,Nginx返回404
EN

Stack Overflow用户
提问于 2014-10-15 13:18:27
回答 2查看 1.8K关注 0票数 0

当我查询在脚本名称后面附加了"path info“的网址时,Nginx返回了一个404,例如http://example.com/index.php/hello。

下面是我的配置:

代码语言:javascript
复制
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$与这个网址不匹配,我也尝试过搜索类似的问题,但没有找到任何有用的东西。

EN

回答 2

Stack Overflow用户

发布于 2014-10-15 14:31:55

使用

位置~ ^.+.php {

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

若要匹配uri中的.php,请拆分参数。

票数 2
EN

Stack Overflow用户

发布于 2016-03-20 05:25:37

这对我来说很有效:

代码语言:javascript
复制
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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26374986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档