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/;
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章