nginx reverse proxy 502 bad gateway error

cruise nginx-forum at nginx.us
Fri Apr 12 16:23:53 UTC 2013


Hello,

I am getting 502 bad gateway error while trying to setup nginx server as
reverse proxy server with caching enabled. Both servers are on seperate
machines, another server having apache web server.

Given below are my config files, please help me.

nginx.conf
---------------------------------------------------------------------------------------------------------------------------------------
user  www www;

worker_processes 1;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this
process.
worker_rlimit_nofile 51200;

events
        {
                use epoll;
                worker_connections 51200;
        }

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

                server_names_hash_bucket_size 128;
                client_header_buffer_size 32k;
                large_client_header_buffers 4 32k;
                client_max_body_size 50m;

                sendfile on;
                tcp_nopush     on;

                keepalive_timeout 60;

                tcp_nodelay on;

                fastcgi_connect_timeout 300;
                fastcgi_send_timeout 300;
                fastcgi_read_timeout 300;
				    fastcgi_read_timeout 300;
                fastcgi_buffer_size 32k;
                fastcgi_buffers 8 16k;
                fastcgi_busy_buffers_size 64k;
                fastcgi_temp_file_write_size 256k;

                gzip on;
                gzip_min_length  1k;
                gzip_buffers     4 16k;
                gzip_http_version 1.0;
                gzip_comp_level 2;
                gzip_types       text/plain application/x-javascript
text/css application/xml;
                gzip_vary on;

                #limit_zone  crawler  $binary_remote_addr  10m;

                #log format
                log_format  access  '$remote_addr - $remote_user
[$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';


include vhost/*.conf;
}


---------------------------------------------------------------------------------------------------------------------------------------


www.example.com.conf
---------------------------------------------------------------------------------------------------------------------------------------
proxy_cache_path /usr/local/nginx/proxy levels=1:2 keys_zone=one:15m
inactive=7d max_size=1000m;

server {
   listen 80;
   server_name www.example.com;
   access_log off;
   error_log off;
   location / {
      proxy_pass http://1.2.3.4:80;
      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;
      proxy_cache one;
      proxy_max_temp_file_size 0;
      client_max_body_size 10m;
      client_body_buffer_size 128k;
      proxy_connect_timeout 90;
      proxy_send_timeout 90;
      proxy_read_timeout 90;
      proxy_buffer_size 4k;
      proxy_buffers 4 32k;
      proxy_busy_buffers_size 64k;
      proxy_temp_file_write_size 64k;
   }
}
server
        {       listen  80;
                server_name example.com;
                rewrite ^/(.*) http://www.example.com/$1 permanent;
        }
---------------------------------------------------------------------------------------------------------------------------------------




Please note www.example.com is replaced with actual domain, and ip 1.2.3.4
is replaced with actual ip address in the original configuration file.

Additional Information : 

I have done the lnmp installation using the script available here :
http://www.ruchirablog.com/lnmp-v08-complete-nginx-auto-installer/

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



More information about the nginx mailing list