A topology when nginx is in reverse-proxy mode? support ?

Maxim Dounin mdounin at mdounin.ru
Sun Feb 5 11:07:05 UTC 2012


Hello!

On Sun, Feb 05, 2012 at 01:02:12PM +0800, Geoge.Q wrote:

> hi all:
> 
> please see the following topology in my test-bed, it always accesses the
> first website in reverse-proxy.
> 
> 1. Topology
> 
>      Outside -------------------[ NAT Device] -----------------[nginx with
> reverse-proxy]----------------Web1 (1.1.1.1:80)
>   [http://2.2.2.2:8000               |
>    |                               |______Web2 (1.1.1.2:80)
>   [http://2.2.2.2:8001            2.2.2.2
> 1.1.1.255
> 
>  2. How to access
> 
>     (1)  Access http://2.2.2.2:8000 from outside to access web1;
>           Access http://2.2.2.2:8001 from outside to access web2;
>     (2) NAT device translated 2.2.2.2 to different internal IP address
> according to port;
>              http://2.2.2.2:8000  =====NAT===> http://1.1.1.1(web1);
>              http://2.2.2.2:8001  =====NAT===> http://1.1.1.2(web2);
>     (3)  NGINX act as reverse proxy;
> 
> 3. issue
>    We configure nginx as reverse proxy, but it always proxy
> (http://1.1.1.1and http:/
> 1.1.1.2) to http://1.1.1.1;
> 
>    nginx configure is as following
> 
>      server {
>            listen 80;
>            server_name 2.2.2.2; // (try 2.2.2.2:8000, it failed)
> 
>             location / {
>                  proxy_pass http://1.1.1.1; # <==========Web1
>                  ....
>             }
>     }
> 
>        server {
>            listen 80;
>            server_name 2.2.2.2; # (try 2.2.2.2:8000, it failed)

As long as hostnames in requests to different sites match exactly 
(nginx doesn't look at ports in Host headers, only at hostnames) - 
you have to use distinct listen sockets on nginx (i.e. distinct 
ports and/or ips).

That is, use something like this:

    server {
        listen 1.1.1.1:80;
        server_name 2.2.2.2;
        ...
    }

    server {
        listen 1.1.1.2:80;
        server_name 2.2.2.2;
        ...
    }

Maxim Dounin



More information about the nginx mailing list