Nginx下ThinkPHP项目支持pathinfo的配置

nginx配置文件如下:

server {
	listen   80;

	root /home/netcec/public_html/thinkphp;
	index index.html index.htm index.php;

	server_name www.book-demo.com book-demo.com

		access_log /var/log/nginx/www.book-demo.com-access.log;
	error_log /var/log/nginx/www.book-demo.com-error.log;

	location ~* ^.+.(gif|jpg|png|css|js|flv|ico|swf)$ {
		access_log        off;
		expires           30d;
	}

	location / {
		if (!-e $request_filename) {  
			rewrite  ^/(.*)$  /index.php/$1  last;  
			break;  
		}  
	}

	location ~ \.php/?.*$ {  
		fastcgi_pass   unix:/var/run/php5-fpm.sock;  
		include        fastcgi.conf;  

                #设置PATH_INFO并改写SCRIPT_FILENAME,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_root$fastcgi_script_name2;  
		fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;  
	}  	
	location ~ /\.ht {
		deny all;
	}
	location ~ /source/protected {
		deny all;
	}
}



2 评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注