Odd reverse proxy behavior

nailxx nginx-forum at nginx.us
Thu Sep 29 20:38:14 UTC 2011

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_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: http://forum.nginx.org/read.php?2,216073,216073#msg-216073

More information about the nginx mailing list