當咱們在使用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