Need help setting nginx up as proxy

djeyewater nginx-forum at nginx.us
Mon Jan 11 14:17:26 MSK 2010


I'm trying to setup nginx as a front-end receiving requests on port 80, and then forwarding them to another nginx installation listening on a different port.

The Nginx on port 80 is working okay, I opened up http://localhost/ and got the 'Welcome to Nginx' message.
The Nginx on port 7776 is working okay, I opened up http://static1.photosite.com:7776/js-min.js and got the page loaded okay.

But when I try to access the same address by port 80 (http://static1.photosite.com/js-min.js), instead of getting the page, I get 502 Bad Gateway.

The conf for Nginx on Port 80 is:

worker_processes  1;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen 80;
        server_name www.photosite.com photosite.com static1.photosite.com static2.photosite.com;
        location / {
            proxy_pass http://127.0.0.1:7776;
        }
    }
}







The conf for the Nginx on port 7776 is:

worker_processes  2;

pid logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    server_names_hash_bucket_size 128;

    sendfile        on;
    keepalive_timeout  10 10;

    gzip  on;
    gzip_comp_level 3;
    gzip_proxied any;
    gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xhtml+xml application/xml+rss text/javascript;
    gzip_disable "MSIE [1-6]\.";
   
    log_format main '$remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent"';

    include sites/*;
}






and relevant part of the site file included:

server {
    listen          7776;
    server_name     static1.photosite.com static2.photosite.com;
   
    error_log  logs/photosite-static1-static2-error.log debug;
    access_log  logs/photosite-static1-static2-access.log  main;

    #Block access to dot files
    location ^~ /. {
        deny all;
    }

    #Fix IP address
    set_real_ip_from   127.0.0.1;
    real_ip_header     X-Forwarded-For;
 
    location / {
        root  /home/djeyewater/webapps/htdocs/photosite/CSI;
        expires max;
    }

    location /Img/desktop {
        add_header Content-Disposition: "$request_filename";
    }
}





Can anyone help me get this working?

Thanks

Dave

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,39702,39702#msg-39702




More information about the nginx mailing list