# Odd reverse proxy behavior

**URL:** <https://www.ruby-forum.com/t/odd-reverse-proxy-behavior/212331>\
**Category:** NGINX\
**Created:** [September 29, 2011, 10:38pm UTC](https://www.ruby-forum.com/t/odd-reverse-proxy-behavior/212331 "2011-09-29T22:38:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 29, 2011, 10:38pm UTC](https://www.ruby-forum.com/t/odd-reverse-proxy-behavior/212331/1 "2011-09-29T22:38:39Z")

</div>

Hi, all!

I’ve stumbled upon a problem I can’t find a solution for many hours in a  
row. I use nginx as a reverse proxy to python/spawning web-server. I’ve  
done it for 1000 times already and all worked fine before this day.

Nginx on a server I’m talking about serves 3 separate projects  
(hostnames) as a reverse proxy. I’ve added fourth. Three existing  
projects continued to work perfectly. But the new one sometimes works  
and sometimes returns 502.

The observation is: once it began to return 502 it would return it on  
every browser refresh. However if I’ll throttle F5 fast, after 5-10  
refreshes it starts to work properly. And vice versa: once it works like  
it should, slow refreshes keep it working, but if I’d throttle F5 again  
or if I’d wait for a minute or so nginx declines back to 502-state.

There is nothing recorded in neither log (access/error nginx/backend) if  
it is in 502-state. The deal is not in a backend. I’ve tried to set  
proxy\_pass to the same value as in a sibling well-working project conf  
and the same story repeats. Problem exists for static resources as well.  
Is this conf cursed?

++++  
user www-data;  
worker\_processes 1;

error\_log /var/log/nginx/error.log debug;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
# multi\_accept on;  
}

http {  
include /etc/nginx/mime.types;

```
access_log /var/log/nginx/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

```

}

#### /etc/nginx/sites-enabled/my-cursed-conf

server {  
listen 80;  
server\_name hostname.iam.listening.to;

```
# Main location
location / {
    proxy_pass http://127.0.0.1:8084;
    proxy_redirect off;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /static/ { alias /srv/some/path/static/; }

```

}

++++

I feel I’ve tried all combinations of buffer-tweaking and none of them  
helped. The system has \> 700 Mb or RAM free and mostly idle CPU. Could  
someone guess what the hell is going on?

Posted at Nginx Forum:

> **[Odd reverse proxy behavior](https://forum.nginx.org/read.php?2,216073,216073#msg-216073)**
>
> Hi, all! I've stumbled upon a problem I can't find a solution for many hours in a row. I use nginx as a reverse proxy to python/spawning web-server. I've done it for 1000 times already and all worked fine before this day. Nginx on a server I'm...

---

<div class="post-metadata">

**Author:** ![nailxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed655f/32.png) [@nailxx](https://www.ruby-forum.com/u/nailxx)\
**Post date:** [September 29, 2011, 11:57pm UTC](https://www.ruby-forum.com/t/odd-reverse-proxy-behavior/212331/2 "2011-09-29T23:57:01Z")

</div>

Got it!

The problem was absolutely not related to nginx configuration. I found  
it when I continued to get 502s even with nginx process down O\_o

I’ve accidentally added two A-records to the DNS-zone with same name but  
different IPs. Looks like the resulting IP was chosen in  
semi-round-robin fashion. And when a not configured server was chosen,  
I’ve got those 502s.

Whew!… Sorry for disturbing.

Posted at Nginx Forum:

> **[Re: Odd reverse proxy behavior](https://forum.nginx.org/read.php?2,216073,216075#msg-216075)**
>
> Hi, all! I've stumbled upon a problem I can't find a solution for many hours in a row. I use nginx as a reverse proxy to python/spawning web-server. I've done it for 1000 times already and all worked fine before this day. Nginx on a server I'm...
