nginx 配置支持pathinfo和url重写 thinkphp5

apache是默认支持pathinfo,而nginx本身是不支持pathinfo 
何为pathinfo?请看这条url127.0.0.1/test.php/a/b/c,/a/b/c即为pathinfo

配置支持pathinfo

location ~ \.php(.*)$ {
		include snippets/fastcgi-php.conf;
	
		## With php-fpm (or other unix sockets):
		fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
		## With php-cgi (or other tcp sockets):
		#fastcgi_pass 127.0.0.1:9000;
        
        fastcgi_param PATH_INFO $1;//添加这一句
}

以上便配置成功,测试   127.0.0.1/xxx/public/index.php/index

配置url重写

当你配置好了pathinfo时,如果此时你运行thinkphp5,需要这样子访问,127.0.0.1/xxx/public/index.php/xxx/xx,每一次访问都需要携带index.php,这时可通过url的重写将index.php隐藏起来

在location / { …. }当中添加下列指令

 if (!-e $request_filename) {
            rewrite  ^/(.*)/public/(.*)$  /$1/public/index.php?s=/$2  last;
        }

/(.*)/public/index.php,index.php前面有几级的目录就需要添加几级的,这个是正则表达式,不理解的请自行百度

猜你喜欢

转载自blog.csdn.net/wyk9916/article/details/84502126