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

2011-12-28 01:26:36 +08:00
 Matata
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只能做一个反向么?
5678 次点击
所在节点    问与答
4 条回复
znithy
2011-12-28 01:38:23 +08:00
可以设置很多个。
Matata
2011-12-28 01:40:40 +08:00
@znithy 两个都是反向到sinaapp去的,但是现在第二个域名怎么做也都是该页无法显示?是第二个代理需要改端口么?
Matata
2011-12-28 02:08:17 +08:00
当我把a.com的配种从nginx删去以后,访问a.com就会到原本c希望代理到的 D上去。
a和c都解析到服务器了。
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;


}

}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/24486

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX