网站制作学习网经验与学习→正文:nginx 获取部分host
字体:

nginx 获取部分host

经验与学习 2023/2/10 17:27:56  点击:不统计

http://%77%77%77%2E%66%6F%72%61%73%70%2E%63%6E
 根据二级或者三级域名进行跳转或设置路径,在server中设置如下

 
server_name  *.forasp.cn # 这里是泛解析
# 下面是将三级域名跳转到对应二级域名,比如  a.b.forasp.cn 会跳转到 b.forasp.cn
if ($host ~* ^(.+)\.([^\.]+)\.forasp\.cn) {
set $third_domain $1; # 这里没有用到三级域名,可以不写,如果需要用,则直接用变量 $third_domain 
set $domain $2; # 将上述表达式中的第二个匹配设置为变量domain
rewrite ^/(.*)$ https://$domain.forasp.cn/$1 permanent;# 将uri匹配 $1 ,比如访问a.b.forasp.cn/cc 则会跳转到b.forasp.cn/cc
}
# 下面则是将 四级域名 进行跳转
if ($host ~* ^(.+)\.([^\.]+)\.([^\.]+)\.forasp\.cn) {
set $domain $3;
rewrite ^/(.*)$ https://$domain.forasp.cn/$1 permanent;
}
 
# 也可以通过nginx proxy 进行域名代理,可以自行定义三级,四级域名。

forasp.cn

·上一篇:header设置不显示nginx php版本 >>    ·下一篇:http接口返回码statusCode >>
推荐文章
最新文章