环境:
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,同时在代理层实现部分独立域名的直接解析。
InBlock.gifupstream www.en.com
InBlock.gif{
InBlock.gif        server 192.168.1.100:81;
InBlock.gif}
InBlock.gif
upstream www.cn.com
InBlock.gif{
InBlock.gif        server 192.168.1.200:81;
InBlock.gif}
InBlock.gif
server
InBlock.gif        {
InBlock.gif                listen 192.168.1.100:80 ;
InBlock.gif                server_name en-style.gcimg.net;
InBlock.gif                index index.html index.htm;
InBlock.gif        location /
InBlock.gif                     {
InBlock.gif                        root /home/web/en-style;        
InBlock.gif                     }
InBlock.gif                access_log    off;
InBlock.gif        }
InBlock.gif
server
InBlock.gif        {
InBlock.gif                listen 192.168.1.100:80;
InBlock.gif                server_name cn-style.gcimg.net;
InBlock.gif                index index.html index.htm;
InBlock.gif        location /
InBlock.gif                     {
InBlock.gif                        root /home/web/cn-style;        
InBlock.gif                     }
InBlock.gif                access_log    off;
InBlock.gif        }
InBlock.gif
server
InBlock.gif        {
InBlock.gif                listen 192.168.1.100:80 default;
InBlock.gif                server_name _;
InBlock.gif                index index.html index.htm;
InBlock.gif        location /
InBlock.gif                     {
InBlock.gif                                proxy_set_header Host    $host;
InBlock.gif                                proxy_set_header X-Forwarded-For    $remote_addr;
InBlock.gif                                proxy_pass http://www.en.com;
InBlock.gif                        }
InBlock.gif                access_log    off;
InBlock.gif        }
InBlock.gif
server
InBlock.gif        {
InBlock.gif                listen 192.168.1.200:80 default;
InBlock.gif                server_name _;
InBlock.gif                index index.html index.htm;
InBlock.gif        location /
InBlock.gif                     {
InBlock.gif                                proxy_set_header Host    $host;
InBlock.gif                                proxy_set_header X-Forwarded-For    $remote_addr;
InBlock.gif                                proxy_pass http://www.cn.com;
InBlock.gif                        }
InBlock.gif             access_log    off;
InBlock.gif        }
出现过的问题:

1,泛域名的配置,要接收所有域名的绑定,使用server_name _;的方式实现

2,当代理层的泛域名配置好后,cn-style.en-style等独立域名的访问都被转到了后端,代理层实现不了独立域名的解析了。
解决方法:独立域名的listen中也配置IP地址,防止被解析到泛域名所指定的服务器上