Heim >Backend-Entwicklung >PHP-Tutorial >让nginx圆满支持Thinkphp的配置

让nginx圆满支持Thinkphp的配置

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:55:571054Durchsuche

让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/?.*$ {<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>}


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

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



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn