# Proxy pass confusion

**URL:** <https://www.ruby-forum.com/t/proxy-pass-confusion/222344>\
**Category:** NGINX\
**Created:** [August 27, 2012, 2:00pm UTC](https://www.ruby-forum.com/t/proxy-pass-confusion/222344 "2012-08-27T14:00:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 27, 2012, 2:00pm UTC](https://www.ruby-forum.com/t/proxy-pass-confusion/222344/1 "2012-08-27T14:00:24Z")

</div>

Here is my server setup:

Amazon load balancer ([loadbalancer.aws.com](http://loadbalancer.aws.com)) → nginx servers in  
reverse-proxy/caching mode → back end PHP servers

If I visit the nginx server directly in my browser, everything works  
perfectly.

If I visit [loadbalancer.aws.com](http://loadbalancer.aws.com), the nginx server redirects me to  
[http://decupstream](http://decupstream), which is what I named the upstream block in my  
configuration. The nginx.conf looks like:

upstream decupstream {  
server 10.167.1.50:8080;  
server 10.160.242.232:8080;  
server 10.222.218.126:8080;  
}

```
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=gop2012:10m;

server {
    listen 80;
    server_name gop-proxy.mycompany.com;

    location / {
      proxy_pass http://decupstream;
      proxy_cache gop;
      proxy_cache_valid 10m;
      proxy_cache_use_stale error timeout invalid_header http_500;
      proxy_next_upstream error timeout invalid_header http_500;
      proxy_cache_lock on;
      proxy_ignore_headers Cache-Control Expires;
      proxy_set_header Host "gop.mycompany.com";
    }
}

```

How do I get nginx to forward requests to the Apache/PHP servers even if  
they don’t come in directly to the nginx box?

-jsd-

---

<div class="post-metadata">

**Author:** ![Jon\_Drukman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@Jon\_Drukman](https://www.ruby-forum.com/u/Jon_Drukman)\
**Post date:** [August 27, 2012, 2:02pm UTC](https://www.ruby-forum.com/t/proxy-pass-confusion/222344/2 "2012-08-27T14:02:03Z")

</div>

On Fri, Aug 24, 2012 at 01:40:27PM -0700, Jon Drukman wrote:

Hi there,

> Amazon load balancer ([loadbalancer.aws.com](http://loadbalancer.aws.com)) → nginx servers in  
> reverse-proxy/caching mode → back end PHP servers
> 
> If I visit the nginx server directly in my browser, everything works  
> perfectly.
> 
> If I visit [loadbalancer.aws.com](http://loadbalancer.aws.com), the nginx server redirects me to  
> [http://decupstream](http://decupstream), which is what I named the upstream block in my  
> configuration.

Are you sure that it is nginx redirecting you, and not the back-end  
servers? Look at the headers from a “curl -i” of a request that fails,  
and see is there any indication that it came from the back-end. Maybe  
compare that with the headers from the same request that succeeds when  
you visit the nginx server directly.

The only way I can think this would happen would be if you didn’t have  
the “proxy\_set\_header Host” line in the actually-running configuration.

The nginx.conf fragment you’ve included fails to load. (“proxy\_cache”  
zone “gop” is unknown.) Can you confirm that “proxy\_set\_header Host”  
is included in the working one, and provide a minimal fragment that  
demonstrates the problem?

For example, if you omit all of the proxy\_cache-related directives, do  
you still see the problem? If so, then you’ve found a simpler test  
case. (And if not, then maybe the cache configuration should be examined  
more closely.)

## f

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