我是靠谱客的博主 精明马里奥,这篇文章主要介绍nginx根据二级域名做请求转发,现在分享给大家,希望可以做个参考。

在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根据二级域名做请求转发内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(96)

评论列表共有 0 条评论

立即
投稿
返回
顶部