首页 > 代码库 > 让nginx完美支持Thinkphp的配置

让nginx完美支持Thinkphp的配置

习惯了用apache后,当第一次用nginx时,把原来的项目(thinkphp框架)部署在新服务器上的时候,惊呆了!

所有的URL模式下都不能正常运行,甚至连css,js文件都不能正常加载。

原因是ngibx不支持pathinfo

主要是需要配置nginx

location / {
            root   D:/wnmp/www;
            index  index.html index.htm;
			#访问路径的文件不存在则重写URL转交给ThinkPHP处理
			if ( !-e $request_filename ) {
			   rewrite  ^/(.*)$  /index.php/$1  last;
			   break;
			}
        }
location ~ \.php/?.*$ {			root        D:/wnmp/www;			fastcgi_pass   127.0.0.1:9001;			fastcgi_index  index.php;			#加载Nginx默认"服务器环境变量"配置			include        fastcgi_params;			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;		}


最后这部分是为了css和js 以及图片等资源

location ~* ^.+\.(jpg|jpeg|gif|png|bmp|css|js|swf)$ {
			access_log off;
			root D:/wnmp/www;
			break;
		}