Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the same problem that most people seem to have with Nginx: 502 bad gateway errors. They are intermittent but typically happen more than once per session, which means my users are probably running into it nearly every time they use the app. I've tried adjusting fastcgi_buffers and fastcgi_buffer_size (in both directions) to no avail. I've tried various other things with the configuration file but nothing seems to work. Here's my config (note that I've stripped away most of the things I've tried, since they didn't work and I didn't want to bloat the file with a bunch of un-related directives):

server {
    root    /usr/share/nginx/www/;
    index   index.php;

    # Make site accessible from http://localhost/
    server_name localhost;

    # Pass PHP scripts to PHP-FPM
    location ~ \.php {
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
    }

    # Lock the site
    location / {
            auth_basic "Administrator Login";
            auth_basic_user_file /usr/share/nginx/.htpasswd;
    }
    # Hide the password file
    location ~ /\. {
            deny all;
    }

    client_max_body_size 8M;
}

I'm running a small Rackspace cloud server, which should be plenty for handling an app with a small user base...

share|improve this question
add comment

1 Answer

Yep, the known Nginx: 502 bad gateway error… ;) I dealt with this issue a little while back. What worked for me was increasing the values of fastcgi_buffers and fastcgi_buffer_size parameters. I added 2 arguments to /etc/nginx/sites-available/default in Nginx:

location ~ \.php$ {
  root /your/site/root;
  fastcgi_index index.php;
  include fastcgi_params;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_pass 127.0.0.1:9000;

  # set these two:
  fastcgi_buffer_size 16k;
  fastcgi_buffers 4 16k;
}

Hope this helps some.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.