Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;

    # 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

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;

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

Hope this helps some.

share|improve this answer

Your Answer


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.