之前没有在意一直都是在Apache下部署,换成Nginx折腾了半天。终于搞定。
#
# The default server
#
server {
listen 80;
server_name **
location / {
root /www/;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php { #去掉后面的$
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$; #增加这一句
fastcgi_param PATH_INFO $fastcgi_path_info; #还有这一句
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /site/www.xxr.so/$fastcgi_script_name;
# 这个是在配置nginx+php整合的时候就改好的$前面的是网站的主目录
include fastcgi_params;
}
}
最后,不要忘了在 php.ini 中将 cgi.fix_pathinfo=0 改为1
nginx 1.6.2 和上面的稍有不同。
server {
listen 80;
server_name meiman.com ;
root "E:/www/ymems";
location / {
index index.html index.htm index.php;
#autoindex on;
##增加下面的内容
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
##增加下面的内容
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
今天换了个环境,发现用上面的方法不管用。在网上找了试试这个管用。
另外也许有的不在根目录,参考下面的。
location / {
if (!-e $request_filename) {
###一级目录下
rewrite ^/(.*)$ /index.php/$1 last;
###域名下的二级目录
#rewrite ^/目录名/(.*)$ /目录名/index.php/$1 last;
}
}
如果你在执行的时候遇到 Access denied. 这样的提示。其它站点非pathinfo可以正常访问那就注释掉:
# fastcgi_param SCRIPT_FILENAME $request_filename;