习惯了用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; }
