本配置示例在ThinkPHP5 环境下亲测有效,二级目录配置与根目录配置完全独立。主要是通过 ^~ 把sub路径的路由全部接收过来,然后在子location里面进行二次路由和解析,比较方便灵活。之前一直以为location是不能嵌套的,通过这次实践,发现这样用的好处了,确实很方便。
server { listen 80 ; index index.php index.html; location ^~ /sub/ { set $subroot /home/peaksite/public/; alias $subroot; if ( !-e $request_filename) { rewrite ^/sub/(.*)$ /sub/index.php/$1 last; break; } location ~ \.php { fastcgi_pass 127.0.0.1:9000; set $scriptname ‘‘; set $pathinfo ‘‘; if ( $uri ~ ^/sub/(.+\.php)($|/.+) ) { set $scriptname $1; set $pathinfo $2; } fastcgi_param SCRIPT_FILENAME $subroot/$scriptname; fastcgi_index index.php?IF_REWRITE=1; fastcgi_param PATH_INFO $pathinfo; fastcgi_param SCRIPT_FILENAME $subroot/$scriptname; include fastcgi_params; } } }
原文地址:https://www.cnblogs.com/theluther/p/9320510.html
时间: 2024-10-11 06:15:46