V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Matata
V2EX  ›  问与答

nginx设置了两个反向代理为何只有一个生效?

  •  
  •   Matata · 2011-12-28 01:26:36 +08:00 · 5668 次点击
    这是一个创建于 4503 天前的主题,其中的信息可能已经有所发展或是发生改变。
    server {
    server_name_in_redirect off;
    listen 80;
    server_name a.com;
    location / {
    proxy_pass http://b.sinaapp.com;
    }
    }

    设置了两个反向代理a to b
    c to d
    a一切正常到b
    C是无法显示网页
    为什么呢?

    一个VPS只能做一个反向么?
    4 条回复    1970-01-01 08:00:00 +08:00
    znithy
        1
    znithy  
       2011-12-28 01:38:23 +08:00
    可以设置很多个。
    Matata
        2
    Matata  
    OP
       2011-12-28 01:40:40 +08:00
    @znithy 两个都是反向到sinaapp去的,但是现在第二个域名怎么做也都是该页无法显示?是第二个代理需要改端口么?
    Matata
        3
    Matata  
    OP
       2011-12-28 02:08:17 +08:00
    当我把a.com的配种从nginx删去以后,访问a.com就会到原本c希望代理到的 D上去。
    a和c都解析到服务器了。
    znithy
        4
    znithy  
       2011-12-28 04:05:44 +08:00
    我特地试了下,没问题。
    直接贴nginx的代码了
    a.weiboes.com反向到http://airweibo.sinaapp.com/
    b.weiboes.com反向到http://shiguangji.sinaapp.com/
    你可以访问下看看,我自己试了没问题。
    代码的subs_filter那行是用来替换输出文本的,你没装替换插件的话就把这行删了。

    ---------------------------------

    server
    {
    listen 80;
    server_name a.weiboes.com;

    location / {
    proxy_redirect off;
    proxy_set_header Host $proxy_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header referer http://airweibo.sinaapp.com/;
    proxy_pass http://airweibo.sinaapp.com/;
    proxy_set_header Accept-Encoding "";
    subs_filter 'airweibo.sinaapp.com' 'a.weiboes.com' g;


    }

    }


    server
    {
    listen 80;
    server_name b.weiboes.com;

    location / {
    proxy_redirect off;
    proxy_set_header Host $proxy_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header referer http://shiguangji.sinaapp.com/;
    proxy_pass http://shiguangji.sinaapp.com/;
    proxy_set_header Accept-Encoding "";
    subs_filter 'shiguangji.sinaapp.com' 'b.weiboes.com' g;


    }

    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2806 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 12:26 · PVG 20:26 · LAX 05:26 · JFK 08:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.