首页 > 代码库 > 让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; }
location ~* ^.+\.(jpg|jpeg|gif|png|bmp|css|js|swf)$ { access_log off; root D:/wnmp/www; break; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。