nginx 不支持 index.php/Module/Controller/Action 这样的 url 路径??
高洛峰
高洛峰 2017-04-11 10:26:03
[PHP讨论组]

正常情况,Apache 针对:

http://test.com/index.php/Module/Controller/Action

这样的访问路径,其会访问 index.php 文件。

可是 nginx 不是这样的!他把 index.php 当成是目录了!继续查找文件,直到:Action 。。。(不知道是否是这样??),总之就是提示找不到页面..郁闷啊,求大神解决小弟的燃眉之急,,谢谢

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(2)
迷茫

配置rewrite啊

天蓬老师

昨天太晚了,头有点昏,被楼上误导,没有分清楚pathinfo和伪静态。
在nginx.conf的 server/location标签中,转发请求给php-fpm时预处理一下pathinfo
把pathinfo转化为query-url形式

    location ~ \.php(.*)$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include        fastcgi_params;
    }

完整的配置参考:

server {
        listen       80;
        server_name  demo;
        root   "/var/html";
        location / {
            index  index.html index.htm index.php;
            #这个可以把index.php去掉  就是demo.com/module/controller/action的形式
            try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号