Home > Backend Development > PHP Tutorial > 让nginx圆满支持Thinkphp的配置

让nginx圆满支持Thinkphp的配置

WBOY
Release: 2016-06-13 11:55:57
Original
1036 people have browsed it

让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;			}        }
Copy after login
location ~ \.php/?.*$ {<span style="white-space:pre">			</span>root        D:/wnmp/www;<span style="white-space:pre">			</span>fastcgi_pass   127.0.0.1:9001;<span style="white-space:pre">			</span>fastcgi_index  index.php;<span style="white-space:pre">			</span>#加载Nginx默认"服务器环境变量"配置<span style="white-space:pre">			</span>include        fastcgi_params;<span style="white-space:pre">			</span>include<span style="white-space:pre">		</span>   fastcgi.conf;<span style="white-space:pre">			</span>#设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量<span style="white-space:pre">			</span>set $fastcgi_script_name2 $fastcgi_script_name;<span style="white-space:pre">			</span>if ( $fastcgi_script_name ~ "^(.+\.php)(/.+)$" ) {<span style="white-space:pre">				</span>set $fastcgi_script_name2 $1;<span style="white-space:pre">				</span>set $path_info $2;<span style="white-space:pre">			</span>}<span style="white-space:pre">			</span>fastcgi_param   PATH_INFO $path_info;<span style="white-space:pre">			</span>fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;<span style="white-space:pre">			</span>fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;<span style="white-space:pre">		</span>}
Copy after login


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

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



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template