Thinkphp is deployed in nginx with 500 or 404 errors. Solution

Source: Internet
Author: User


Nginx is a high-performance and concurrent server software, which is slightly more complicated than apache in configuration.
A locally deployed thinkphp framework, when deployed to the server, throws a 404 error due to permission issues at first, and then throws a 500 error after chown, but the homepage can be accessed.
The review should be a pseudo-static rewrite problem. I found a lot of documents and the solution is as follows:

You should set

Location ~ . * \. (Php | php5 )? $
{
# Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Include fastcgi. conf;
}


Changed:

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;
}

Solution: When configuring the site, the conf file should change the path of the entire request to the server, that is, from "location ~ \. Php "in braces, the default nginxlocation row header location ~ . * \. (Php | php5 )? $ Also needs to be modified. Change the location of the first line to the top. The 500 server error "thinkphp 500 error" can be solved"

Nginx running error 404 Error-file solution not found


Solution 1: modify ThinkPHP settings without using PATH_INFO

Solution 2 (recommended): modify nginx settings and support for PATH_INFO

Modify nginx. conf and fastcgi-params
Set

Php geshi ">

Location ~ \. Php $ {

Change

Location ~ \. Php /?. * $ {

Set

Fastcgi_param SCRIPT_FILENAME $ document_root2 $ fastcgi_script_name;

Change


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_root2 $ fastcgi_script_name2;

Set

Fastcgi_param SCRIPT_NAME $ fastcgi_script_name;

Change

Fastcgi_param SCRIPT_NAME $ fastcgi_script_name2;

The complete nginx VM block configuration is as follows:

Server {
Listen 80;
Server_name www.amiku.cn amiku.cn;
Root/www_amiku_cn;
Include/www_amiku_cn/. htaccess;
Index index.html index.htm index. php;
Location ~ . * \. (Php | php5 )/?. * $
{
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
# Fastcgi_split_path_info ^ (. + \. php) (. *) $;
# Fastcgi_param PATH_INFO $ fastcgi_path_info;
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/www_amiku_cn $ real_script_name;
Fastcgi_param SCRIPT_NAME $ real_script_name;
Fastcgi_param PATH_INFO $ path_info;
Fcinclude GI. conf;
}
}

In addition, the modified. htaccess is attached to meet the different pseudo-static nginx and apache server rules.


# RewriteEngine on
# RewriteRule rule index.html $ index. php/Index/index
# RewriteRule restart ([a-z?[a-z={}.html $ index. php/$1/index
# RewriteRule publish ([a-z?[a-z=00000000-([a-z?##.html $ index. php/$1/$2
# RewriteRule publish ([a-zjw[a-zjw00000000-([a-z1_0000-([a-z1_00000000-(%0-91_00000000.html $ index. php/$1/$2/$3/$4
# RewriteRule ^ ([A-Z] [a-z] +)-([a-z] +)-([a-z] +) -([\ x00-\ xff000000000000-(%a-z000000000000-(%0-9000000000000-(%a-z0000000000000000-(%0-9000000000000.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=00000000-(?a-z=0000-(=a-z=00000000-(%0-920.00000000.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
-92.16.html $1/index. php/$2/$3/$4/$5/$6/$7/$8/$9;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.