在server{}段中添加以下location:
location / {
#root html;
#index index.html index.htm;
#处理二级域名fund.cmbchina.com转发
if ($http_host ~* "^(.*?).cmbchina.com$") { #正则表达式
set $domain $1; #设置变量
}
if ($domain ~* "fund") {
proxy_pass http://192.168.1.22:88; #域名中有fund,转发到88端口
}
#if ($domain ~* "cms") {
# proxy_pass http://192.168.1.22:99; #域名中有cms,转发到9090端口
#}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#将代理服务器收到的用户的真实IP信息传给后端服务器
#默认转发(不符合上文if条件的,默认转发至以下)
proxy_pass http://localhost:8090/cmbwww/;
}
最后
以上就是精明马里奥最近收集整理的关于nginx根据二级域名做请求转发的全部内容,更多相关nginx根据二级域名做请求转发内容请搜索靠谱客的其他文章。
发表评论 取消回复