环境:
centos 5.4+nginx反向代理(端口使用80)+nginx web服务(端口使用81)
IP1:192.168.1.100
IP2:192.168.1.200
需求:
1,两个独立域名(cn-style.gcimg.net,en-style.gcimg.net)的server,需在反向代理层实现,不转到后端处理
2,配置两个泛域名server,根据listen 的IP地址分别反向代理到后端的不同web server
目的:
让服务器实现可接收任何域名的绑定,根据绑定IP的不同,调用后端不同的server,同时在代理层实现部分独立域名的直接解析。

upstream www.en.com

{

server 192.168.1.100:81;

}

upstream www.cn.com

{

server 192.168.1.200:81;

}

server

{

listen 192.168.1.100:80 ;

server_name en-style.gcimg.net;

index index.html index.htm;

location /

{

root /home/web/en-style;

}

access_log off;

}

server

{

listen 192.168.1.100:80;

server_name cn-style.gcimg.net;

index index.html index.htm;

location /

{

root /home/web/cn-style;

}

access_log off;

}

server

{

listen 192.168.1.100:80
default;

server_name _;

index index.html index.htm;

location /

{

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;

proxy_pass http:
//www.en.com;
}

access_log off;

}

server

{

listen 192.168.1.200:80
default;

server_name _;

index index.html index.htm;

location /

{

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;

proxy_pass http:
//www.cn.com;
}

access_log off;

}
出现过的问题:
1,泛域名的配置,要接收所有域名的绑定,使用server_name _;的方式实现
2,当代理层的泛域名配置好后,cn-style.en-style等独立域名的访问都被转到了后端,代理层实现不了独立域名的解析了。
解决方法:独立域名的listen中也配置IP地址,防止被解析到泛域名所指定的服务器上
转载于:https://blog.51cto.com/liguxk/455303