时间: 2010-06-14 / 分类: WEB后端编程 - 开发与实践 / 浏览次数: / 1 个评论 发表评论
ThinkPHP在nginx下的出错伪静态映射配置
WEB前端开发中的一些编程风格和书...
黄金分割与摄影构图
12条经典摄影技巧
CSS Hack浏览器兼容IE6+IE7+IE8+IE9+FF

ThinkPHP在Apache下运行很正常,在nginx下运行出错,提示找不到文件,这是一个nginx设置的问题,和ThinkPHP无关,由于nginx默认设置不处理ThinkPHP所使用的PATH_INFO,查看nginx日志即可看出。

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

解决方法二(推荐):修改nginx设置,支持PATH_INFO

修改nginx.conf和fastcgi-params

location ~ \.$ {

修改为

location ~ \.php/?.*$ {

_param SCRIPT_FILENAME $document_root2$_script_name;

修改为

set $fastcgi_script_name2 $fastcgi_script_name;
if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$”) {
set $fastcgi_script_name2 $1;
set $ $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
# ^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

^(.*)/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;

  站点地图 | 关于我 | 返回顶部
Copyright © 2001-2013 { amiku.cn | zhangshunjin.com }. Powered by 

阿米酷

张顺金


浙ICP备11002820号-1