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

**URL:** <https://www.ruby-forum.com/t/a-topology-when-nginx-is-in-reverse-proxy-mode-support/216444>\
**Category:** NGINX\
**Created:** [February 5, 2012, 6:02am UTC](https://www.ruby-forum.com/t/a-topology-when-nginx-is-in-reverse-proxy-mode-support/216444 "2012-02-05T06:02:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 5, 2012, 6:02am UTC](https://www.ruby-forum.com/t/a-topology-when-nginx-is-in-reverse-proxy-mode-support/216444/1 "2012-02-05T06:02:35Z")

</div>

hi all:

please see the following topology in my test-bed, it always accesses the  
first website in reverse-proxy.

1. Topology

2. How to access

3. issue  
We configure nginx as reverse proxy, but it always proxy  
([http://1.1.1.1and](http://1.1.1.1and) http:/  
1.1.1.2) to [http://1.1.1.1](http://1.1.1.1);

4. I try to change the configuration, it is failed.

thanks

George. Alex.

---

<div class="post-metadata">

**Author:** ![Geoge.Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e9c0ed/32.png) [@Geoge.Q](https://www.ruby-forum.com/u/Geoge.Q)\
**Post date:** [February 5, 2012, 12:07pm UTC](https://www.ruby-forum.com/t/a-topology-when-nginx-is-in-reverse-proxy-mode-support/216444/2 "2012-02-05T12:07:57Z")

</div>

Hello!

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

> | |\_\_\_\_\_\_Web2 (1.1.1.2:80)  
> [http://2.2.2.2:8001](http://2.2.2.2:8001) =====NAT===\> [http://1.1.1.2](http://1.1.1.2)(web2);  
> 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 D.

---

<div class="post-metadata">

**Author:** ![Geoge.Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e9c0ed/32.png) [@Geoge.Q](https://www.ruby-forum.com/u/Geoge.Q)\
**Post date:** [February 5, 2012, 5:53pm UTC](https://www.ruby-forum.com/t/a-topology-when-nginx-is-in-reverse-proxy-mode-support/216444/3 "2012-02-05T17:53:02Z")

</div>

Thanks Max and Francis.  
I will try.

George.Alex.

---

<div class="post-metadata">

**Author:** ![Geoge.Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e9c0ed/32.png) [@Geoge.Q](https://www.ruby-forum.com/u/Geoge.Q)\
**Post date:** [February 5, 2012, 12:17pm UTC](https://www.ruby-forum.com/t/a-topology-when-nginx-is-in-reverse-proxy-mode-support/216444/4 "2012-02-05T12:17:51Z")

</div>

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

Hi there,

I’m afraid I’m not able to understand the topology. So I’ll make some  
guesses, and perhaps you can say where I have gone wrong.

> 1. How to access

So 2.2.2.2 is the address of the NAT device, and it sends any inbound  
traffic to port 8000, to internal web1:80; and it sends any inbound  
traffic to port 8001, to internal web2:80?

That should just work, with no need for nginx anywhere.

So that’s presumably not what you want.

Perhaps you have nginx on some other internal server, that the NAT  
device  
sends the traffic to? Or perhaps nginx is running on the NAT device,  
so NAT isn’t needed at all?

> 1. issue  
> We configure nginx as reverse proxy, but it always proxy  
> ([http://1.1.1.1and](http://1.1.1.1and) http:/  
> 1.1.1.2) to [http://1.1.1.1](http://1.1.1.1);

That is the port on the nginx server that nginx listens to, and is  
the port that the traffic to nginx must be sent to. I suspect that it  
should be 8000 or 8001; but when the network topology is clear, it will  
be clear what that will be.

> ```
> server_name 2.2.2.2; // (try 2.2.2.2:8000, it failed)
> 
> ```

That is the name in the Host: header that the client sends. If more than  
one nginx server{} listens on the same ip:port, it is used to choose  
which server{} is used.

> ```
> server {
> listen 80;
> server_name 2.2.2.2; # (try 2.2.2.2:8000, it failed)
> 
> ```

This is the same listen/server\_name as the first one, so will never  
match.

> 1. I try to change the configuration, it is failed.

Because of listen/server\_name, your second server{} block will never be  
used, so no traffic will go to web2.

So: have nginx listening on two different ports, or on two different  
addresses, or use different Host: names in the requests.

(But since I don’t see where nginx fits in to the topology in the first  
place, I guess I must have missed something.)

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Geoge.Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e9c0ed/32.png) [@Geoge.Q](https://www.ruby-forum.com/u/Geoge.Q)\
**Post date:** [February 6, 2012, 2:57pm UTC](https://www.ruby-forum.com/t/a-topology-when-nginx-is-in-reverse-proxy-mode-support/216444/5 "2012-02-06T14:57:46Z")

</div>

Hello,

Is there a possibility to use the satisfy any option with NGINX as a  
loadbalancer?

We normally use “satisfy any” on our apache webservers but for  
authentication/caching reasons we want to put it in the NGINX LB config.

Is there a way to make the location directive accept and pass on the  
“satisfy any” option to the webservers?

Just for your information, we use NGINX purely as a loadbalancer.

Thank you.

Regards,

Jaap van Arragon
