thinkphp部署在nginx下 500错误或404错误解决办法ww

2019-10-03 作者:计算机教程   |   浏览(169)

 rewrite  ^/Public/Min/(.*)$  /Public/Min/index.php/$1  last;
 rewrite ^([a-z]=.*) /Public/Min/index.php?$1 last; 
        #访问路径的文件不存在则重写URL转交给ThinkPHP处理 
        if (!-e $request_filename) { 
           rewrite  ^/(.*)$  /index.php/$1  last;
           break; 
        } 
    } 
    location ~ .php/?.*$ { 
        fastcgi_pass   127.0.0.1:9000; 
        fastcgi_index  index.php; 
        #加载Nginx默认"服务器环境变量"配置 
        include        fastcgi.conf; 
         
        #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量 
        set $fastcgi_script_name2 $fastcgi_script_name; 
        if ($fastcgi_script_name ~ "^(. .php)(/. )$") { 
            set $fastcgi_script_name2 $1; 
            set $path_info $2; 
        } 
        fastcgi_param   PATH_INFO $path_info; 
        fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2; 
        fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2; 
    } 
}

完整的nginx虚拟主机区块配置如下:

        location / { 
        index  index.htm index.html index.php admin.php; 

nginx下运行出错404错误-找不到文件解决办法

主要是nginx配置文件的配置方法,修改配置文件如下:

php geshi">

[代码]bash代码:
server {
        listen  80;
        server_name  www.php2.cc;#这里是站点url
 root   /home/www/php2;#这里是站点根目录

修改为

location ~ .php/?.*$ {

更改为:

解决方法一:修改ThinkPHP设置,不使用PATH_INFO

修改为

fastcgi_param SCRIPT_FILENAME $document_root2$fastcgi_script_name;

location ~ .php
{
fastcgi_pass   127.0.0.1:9000;
fastcgi_index index.php;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(. ?.php)(/. )$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /mnt/khdb1/wwwroot$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include  /alidata/server/nginx/conf/fastcgi_params;
}

#RewriteEngine on
#RewriteRule ^index.html$ index.php/Index/index
#RewriteRule ^([A-Z][a-z] ).html$ index.php/$1/index
#RewriteRule ^([A-Z][a-z] )-([a-z] ).html$ index.php/$1/$2
#RewriteRule ^([A-Z][a-z] )-([a-z] )-([a-z] )-([0-9] ).html$ index.php/$1/$2/$3/$4
#RewriteRule ^([A-Z][a-z] )-([a-z] )-([a-z] )-([x00-xff] )-([a-z] )-([0-9] )-([a-z] )-([0-9] ).html$ index.php/$1/$2/$3/$4/$5/$6/$7/$8 rewrite ^(.*)/index.html$ $1/index.php/Index/index;
rewrite ^(.*)/([A-Z][a-z] ).html$ $1/index.php/$2/index;
rewrite ^(.*)/([A-Z][a-z] )-([a-z] ).html$ $1/index.php/$2/$3;
rewrite ^(.*)/([A-Z][a-z] )-([a-z] )-([a-z] )-([0-9] ).html$ $1/index.php/$2/$3/$4/$5;
rewrite ^(.*)/([A-Z][a-z] )-([a-z] )-([a-z] )-([x00-xff] )-([a-z] )-([0-9] )-([a-z] )-([0
-9] ).html$ $1/index.php/$2/$3/$4/$5/$6/$7/$8/$9;

解决方法二(推荐):修改nginx设置,支持PATH_www.2003.com,INFO

修改nginx.conf和fastcgi-params

本文由www.2003.com发布于计算机教程,转载请注明出处:thinkphp部署在nginx下 500错误或404错误解决办法ww

关键词: