求一个 Nginx 下泛域名反代的规则 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
michelh
V2EX    NGINX

求一个 Nginx 下泛域名反代的规则

  •  
  •   michelh 2014 年 3 月 29 日 5267 次点击
    这是一个创建于 4319 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在nginx下,用泛域名反代泛域名,
    类似这样的:
    it.x.123.com 反代 it.y.abc.com
    news.x.123.com 反代 news.y.abc.com
    ......
    *.x.123.com 反代 *.y.abc.com
    这样的规则应该怎么写呢?
    谢谢大家!
    15 条回复    2014-05-06 18:14:03 +08:00
    maga
        1
    maga  
       2014 年 3 月 30 日 via iPhone   1
    rewrite 写个正则匹配?
    xoxo
        2
    xoxo  
       2014 年 3 月 30 日   2
    server{

    server_name ~^(?<prefix>.+)\.x\.123\.com$;
    ...

    location / {
    set $hostbase '.y.abc.com';
    set $host2proxy $prefix$hostbase ;
    proxy_pass $host2proxy;
    ....
    }

    }


    i will be glad if works...
    hourui
        3
    hourui  
       2014 年 3 月 30 日   3
    首先 server_name ~^it\.(?<subdomain>[^\.]+)\.123\.com$;
    然后 proxy_pass http://it.$subdomain.abc.com/;

    大功告成
    xsziran
        4
    xsziran  
       2014 年 3 月 30 日   1
    https://code.google.com/p/7ghost/
    这个应该可以 不过好像停止开发了
    michelh
        5
    michelh  
    OP
       2014 年 3 月 30 日
    @xoxo 500错误了
    ysjdx
        6
    ysjdx  
       2014 年 3 月 31 日   1
    server {
    listen [::]:80;
    server_name *.x.123.com;
    location / {
    if ($host ~* ^(.*).x.123.com$) {
    set $domain $1;
    proxy_pass http://$domain.y.abc.com;
    }
    }
    }
    michelh
        7
    michelh  
    OP
       2014 年 3 月 31 日
    @ysjdx 也不行,500错误
    michelh
        8
    michelh  
    OP
       2014 年 3 月 31 日
    @xsziran Nginx反代效率高一些 :)
    ysjdx
        9
    ysjdx  
       2014 年 4 月 3 日
    @michelh 没道理啊 500时候的日志是什么?这个我以前测试过。
    michelh
        10
    michelh  
    OP
       2014 年 4 月 3 日
    @ysjdx 113.110.xxx.xxx - - [03/Apr/2014:16:03:01 +0800] "GET /favicon.ico HTTP/1.1" 502 568 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
    michelh
        11
    michelh  
    OP
       2014 年 4 月 3 日
    @ysjdx 现在测试是502
    coolloyal
        12
    coolloyal  
       2014 年 4 月 13 日   1
    @ysjdx
    我这也是这个情况502错误,请问他的问题解决了吗?
    server {
    listen 80;
    server_name ~^(www\.)?(?<domain>.+)\..+$;
    index index.php index.html index.htm;

    location / {
    proxy_pass http://$domain.xxx.com/;
    }
    }
    ysjdx
        13
    ysjdx  
       2014 年 5 月 3 日
    @michelh 问题解决了么?
    ysjdx
        14
    ysjdx  
       2014 年 5 月 3 日
    @coolloyal 我以前测试是可以用的啊
    michelh
        15
    michelh  
    OP
       2014 年 5 月 6 日
    @ysjdx 没有,以前也这么设置过,不记得是怎么写的
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1088 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 18:26 PVG 02:26 LAX 10:26 JFK 13:26
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86