当咱们在使用Nginx来运行Think PHP写的网站项目,在访问时,可能会出现:Access denied , 如图:php
发生错误的缘由是:Nginx下不支持PATH_INFOnginx
既然Nginx不支持PATH_INFO , 那么咱们应该对nginx进行配置,使其支持PATH_INFO (我以CentOS为例)php-fpm
进入 /usr/local/php/etc/php.ini , 将cgi.fix_pathinfo的值设为1,如图: 网站
在进入 /usr/local/nginx/conf/nginx.conf , 添加以下内内容:.net
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;
添加位置如图所示:rest
在CentOS分别运行命令:code
service php-fpm restart service nginx restart
如何其上方法不奏效,能够看看其余的blog, 例如: https://blog.csdn.net/w6611415/article/details/40716563blog