为什么需要配置
当我们在使用Nginx来运行Think PHP写的网站项目,在访问时,可能会出现:Access denied , 如图:
发生错误的原因是:Nginx下不支持PATH_INFO
如何解决这个问题
既然Nginx不支持PATH_INFO , 那么我们应该对nginx进行配置,使其支持PATH_INFO (我以CentOS为例)
第一步:
进入 /usr/local/php/etc/php.ini , 将cgi.fix_pathinfo的值设为1,如图:
在进入 /usr/local/nginx/conf/nginx.conf , 添加如下内内容:
location / {
#try_files $uri $uri/ /index.php?$query_string;
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
添加位置如图所示:
第二步:
在CentOS分别运行命令:
service php-fpm restart
service nginx restart
拓展
如何其上方法不奏效,可以看看其他的blog, 例如: https://blog.csdn.net/w6611415/article/details/40716563