nginx是一个高性能并发的服务器软件,配置方面要稍微比apache复杂一点点。
本地部署成功的一个thinkphp框架,部署到服务器的时候,刚开始因为权限问题抛出404错误,然后chown之后,抛出了500的错误,但是首页能够访问。
复查,应该是伪静态rewrite出现问题了,找了好多文献,解决方案如下:
应该将
location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
更改为:
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;
}
解决方案的思路:是由于在配置站点的时候,conf文件应该将整个对服务器的请求更改路径,即从“ location ~ .php” 这个开始的大括号内的,默认的nginxlocation行头location ~ .*.(php|php5)?$也要改。包括第一行的location都要修改为最上面。就可以解决抛出的500服务器错误“thinkphp 500错误”
nginx下运行出错404错误-找不到文件解决办法
解决方法一:修改ThinkPHP设置,不使用PATH_INFO
解决方法二(推荐):修改nginx设置,支持PATH_INFO
修改nginx.conf和fastcgi-params
将
php geshi">
location ~ .php$ {
修改为
location ~ .php/?.*$ {
将
fastcgi_param SCRIPT_FILENAME $document_root2$fastcgi_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_root2$fastcgi_script_name2;
将
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
修改为
fastcgi_param SCRIPT_NAME $fastcgi_script_name2;
完整的nginx虚拟主机区块配置如下:
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;
include fcgi.conf;
}
}
另外附贴修改过的.htaccess,以满足nginx的伪静态和apache服务器的规则不同。
#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;