FirePHP on Nginx: 502 Bad Gateway


We have switched from Apache to Nginx a month ago. PHP is running on FastCGI using PHP-FPM. I have just recently tried to debug our app using FirePHP and got a 502 Bad Gateway response from Nginx. It looks like Nginx by default limits the header output. This is the error in Nginx’s error log:

2011/09/21 09:36:16 [error] 816#0: *5 upstream sent too big header while reading response header from upstream,
  client: 192.168.56.1, server: v.piclyf.com, request: "GET /pics HTTP/1.1",
  upstream: "fastcgi://127.0.0.1:9000", host: "v.piclyf.com", referrer: "http://v.piclyf.com/dashboard"

The fix that I found is to increase the values of fastcgi_buffer_size and fastcgi_buffers. Add these 2 directives to your PHP FastCGI config in Nginx (i.e. /etc/nginx/sites-available/default):

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;
}