ThinkPHP6 二级目录安装
由于某些特殊原因,可能需要将thinkphp系统安装到二级目录中,可参考以下操作(仅供参考):
网站目录:/www/wwwroot/website
运行目录:/subdir/public
伪静态:
location ~ .*\.(txt|TXT|gif|GIF|jpg|JPG|jpeg|JPEG|png|PNG|bmp|BMP|swf|SWF|css|CSS|js|JS|ico|ICO|doc|DOC|xls|XLS|xlsx|XLSX|docx|DOCX|json|JSON|woff2|WOFF2|woff|WOFF|ttf|TTF|pdf|PDF|zip|ZIP|rar|RAR|7z|7Z|svg|cur|map|properties|bcmap|htm|gz|log)$
{
valid_referers xxx.cn *.yyy.cn;
if ($invalid_referer){
return 404;
}
rewrite ^/subdir/(.*)$ /$1 last; break;
}
set $flag "";
location /subdir/ {
index index.php;
if ($request_uri ~* (get_file|get_auth_file|download|auth_download)){
set $flag "${flag}1";
}
if ($http_referer !~* (xxx|yyy)){
set $flag "${flag}1";
}
if ($flag = '11'){
return 404;
}
if (!-e $request_filename){
rewrite ^/subdir/(.*)$ /index.php?s=$1 last; break;
}
}
Nginx配置:root /www/wwwroot/website/subdir/public;
ThinkPHP源码修改以支持二级目录访问
- 修改
helper.php
中url
方法默认domain
参数为:true - 修改
Url.php
中parseDomain
方法返回值为:return $scheme . $domain .'/subdir'
Route::buildUrl($data['avatar'])->suffix(false)->domain(true)->build();