Nginx支持pathinfo配置【亲测可用】

星期日 上午 01:03 狂奔的蜗牛 服务器技术 3958 views
1
Comments

Error: 404 (Pathinfo error)

In some framework (like thinkphp, cakephp) or CMS, they need the pathinfo function.

1. Edit the file /etc/php/php.ini, make sure

cgi.fix_pathinfo=1

2. Edit /etc/nginx/conf/nginx.conf, comment

location ~ \.php$ {
...
}

to

#location ~ \.php$ {
#...
#}

Then add the follows,(PS:只要把下面的/srv/http/nginx修改为自己的网站的根目录的绝对路径就可以了,比如d:/wwwroot其它部分不用修改

location ~ ^(.+\.php)(.*)$ {
  root   /srv/http/nginx;
  #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock; 	
  fastcgi_pass   127.0.0.1:9000; #Un-comment this and comment "fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;" if you are not using php-fpm.
  fastcgi_index  index.php;
  set $document_root2 $document_root;
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") {	set $document_root2 $1$2; }
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") {	set $document_root2 $1$2; }
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") {	set $document_root2 $1$2; }
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") {	set $document_root2 $1$2; }
  fastcgi_split_path_info ^(.+\.php)(.*)$;
  fastcgi_param	SCRIPT_FILENAME	$document_root2$fastcgi_script_name;
  fastcgi_param	PATH_INFO	$fastcgi_path_info;
  fastcgi_param	PATH_TRANSLATED	$document_root2$fastcgi_path_info;
  include	fastcgi_params;
  fastcgi_param  DOCUMENT_ROOT      $document_root2;
}
来源:https://wiki.archlinux.org/index.php/Nginx
nginx,pathinfo 2012/05/26 01:09:48
评论(1)
1楼 母婴B2b 评论时间:2016-06-22 13:28:21 引用
感谢博主的分享~
共 1 个评论 1/1 页

发表评论

引用成功取消引用×

昵称*: 邮箱*: 网址:

最多可输入300字符 验证码*:


Process: 0.058s | DB :18 queries | UseMem:2,333 kb