求普及反向代理? - V2EX
cdredfox

求普及反向代理?

  •  
  •   cdredfox Sep 26, 2012 3831 views
    This topic created in 4976 days ago, the information mentioned may be changed or developed.
    谁能帮我普及一下反向代理呀?google了一把,大概明白是怎么一回事。但是我有个具体的Case,不知道是否可以做到:

    假设我有个站 test.abc.com 是个二级域名,这个不支持或名绑定,我有一个域名,比如www.test.com我现在想把www.test.com反向代理到test.abc.com上面,即使用www.test.com上面访问的是test.abc.com是否可以?类似于cname的效果。
    7 replie    1970-01-01 08:00:00 +08:00
    TONYHEAD
        1
    TONYHEAD  
       Sep 26, 2012
    可以的,apache的话可以把下面的代码写入www.test.com下的.htaccess文件

    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*)$ http://test.abc.com/$1 [P]
    cdredfox
        2
    cdredfox  
    OP
       Sep 26, 2012
    反向代理是不是还需要 test.abc.com 这个站支持才行?如果不支持,也不能从 www.test.com 上面反向代理过去是吗?
    feiandxs
        3
    feiandxs  
       Sep 26, 2012
    不用
    在nginx里可以做到的
    默认nginx转发$host ,包含域名
    你可以把$host改成test.abc.com
    这样nginx就会接收到www.test.com但是给后端发送test.abc.com返回的时候再给用户发送www.test.com
    无需后端服务器的支持。
    cdredfox
        4
    cdredfox  
    OP
       Sep 26, 2012
    @feiandxs 但是很奇怪,我刚刚试了一下,貌似不行,不知道是否我的配置是否有问题,我是在cloudfoundry上的一个应用,就不能代理过去,直接报404了,如果我改成转发到twitter就可以,所以我刚刚才问是不是需要后端支持。
    cdredfox
        5
    cdredfox  
    OP
       Sep 26, 2012
    @feiandxs 附上我的配置
    server
    {
    listen 80;
    server_name test.com;
    location / {
    proxy_pass http://zhekoujie.cloudfoundry.com/;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    }
    yangg
        6
    yangg  
       Sep 26, 2012
    加上proxy_set_header Host zhekoujie.cloudfoundry.com;
    试试
    cdredfox
        7
    cdredfox  
    OP
       Oct 24, 2012
    我加上这个设置后,还是一样的,404找不到的错
    About     Help     Advertise     Blog     API     FAQ     Solana     5673 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 39ms UTC 06:52 PVG 14:52 LAX 23:52 JFK 02:52
    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