我在使用Nginx+php基于ThinkPHP学习时,基于PATHINFO访问直接出现404错误,原来是Nginx不支持。下面分享一下解决方式
ThinkPHP采用单一入口模式访问应用,下面的访问是等效的:
http://serverName/index.php
http://serverName/index.php/Home/Index/index
这种URL模式就是系统默认的PATHINFO模式,不同的URL模式获取模块和操作的方法不同,ThinkPHP支持的URL模式有四种:普通模式、PATHINFO、REWRITE和兼容模式。
修改nginx.conf文件:
- location ~ .+.php($|/){
- #root html;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_split_path_info ^(.+.php)(/.*)$;
- fastcgi_param PATH_INFO $fastcgi_path_info;
- fastcgi_param SCRIPT_FILENAME D:/www$fastcgi_script_name;
- include fastcgi_params;
- }
收藏