ThinkPHP项目在Nginx上运行的配置问题

为何须要配置

当咱们在使用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

相关文章
相关标签/搜索