title: How to disable Nginx double gzip encoding when fastcgi backend occasionally serves gzipped with content-encoding?
body: <p>Is there any clever way to trick nginx to stop gzip if the backend already has set the "content-encoding" header?</p>
  
  <p>Nginx is configured to gzip the output from the php fastcgi backend.</p>
  
  <p>This works great in 99% of the cases.</p>
  
  <p>Except on rare occasion php will send a raw gzipped file and attach a <code>Content-Encoding: gzip</code> header.</p>
  
  <p>Nginx unfortunately will go right ahead and try to gzip that content a second time.</p>
  
  <p>The produces a double <code>content-encoding: gzip</code> <code>content-encoding: gzip</code> header and double-encoded gzipped body.</p>
  
  <p>Most modern browsers can handle this, Firefox, Chrome.</p>
  
  <p>IE8 cannot, Safari mobile cannot, old Safari 5 for Windows cannot - instead they will show garbled gzipped content because it merges the content-encoding headers and only decodes the gzipped body once.</p>
  
  <p>Thanks for any ideas.</p>