下面的配置是我在从apache转到Nginx 对ThinkPHP的PATHINFO模式配置的,
1:根目录为/var/www/html
2:有两个manager和server目录,
如 请求 /manager/test/ 和 /server/test/ 都会定向到manager/index.php和server/index.php
3: 其他所有的请求都定向到 /index.php
本人Nginx版本1.6.1 php版本 5.4.5
access_log logs/ww2_com_80.log main;
root /var/www/html;
index index.htm index.html index.php;
default_type 'text/plain';
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#加载Nginx默认"服务器环境变量"配置
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location ~ /(server|manager)($|/)(.*) {
try_files $uri /$1/index.php$2$3?$query_string;
}#$1, $2 ,$3 分别对应了上面三个括号匹配的内容
location / {
try_files $uri /index.php$uri?$query_string;
#使用try_files 做定向必须在最后指定query_string变量,否则php取不到GET请求参数
}
上面配置,有问题的地方大家指出来。