Nginx 开启PATHINFO支持ThinkPHP框架实例

ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL' => 2 即可。在Apache下只需要开启mod_rewrite模块就可以正常访问了,但是Nginx中默认是不支持PATHINFO的,所以nginx默认情况下是不支持ThinkPHP的。不过我们可以通过修改nginx的配置文件来让其支持ThinkPHP。

虚拟主机配置文件:  nginx/conf/vhost/127.0.0.1_8090.conf

server {
	listen			8040;
	server_name		127.0.0.1:8040;

	access_log		logs/127.0.0.1_8040.access.log  main;

    location / {        
		root          /www/jingchang/jc_live;
		if (!-e $request_filename) {
		    rewrite  ^/(.*)$  /index.php/$1  last;
		            break;
		    }
	}
	 
	location ~ \.php {
        root         /www/jingchang/jc_live;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		include fastcgi.conf;
		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 $document_root$real_script_name;
		fastcgi_param SCRIPT_NAME $real_script_name;
		fastcgi_param PATH_INFO $path_info;
	}	
}
posted @ 2016-07-19 07:24  52php  阅读(494)  评论(0编辑  收藏  举报