Skip to content

Instantly share code, notes, and snippets.

@neerolyte
Last active August 8, 2017 23:09
Show Gist options
  • Save neerolyte/752f915736d133f170fc62a04f642de0 to your computer and use it in GitHub Desktop.
Save neerolyte/752f915736d133f170fc62a04f642de0 to your computer and use it in GitHub Desktop.
nginx too big header

Raising the buffers is the default reaction to the nginx error upstream sent too big header while reading response header from upstream with php-fpm and fcgi, but it doesn't solve the problem, just makes it harder to hit.

Put this in a .php file somewhere:

<?php
for ($i = 0; $i<$_GET['iterations']; $i++)
        error_log(str_pad("a", $_GET['size'], "a"));
echo "got here\n";

Corrupt fpm error_log so it writes errors to stderr instead of a file:

bash-4.1# grep error_log /etc/php-fpm.d/foo.conf
php_admin_value[error_log] = /var/asdf/asdf/asdf.log

Restart fpm (you can figure this bit out).

Compare 502 errors with different error sizes/iterations...

Native configuration:

bash-4.1# for it in {30..200..3}; do for size in {100..250..3}; do echo "size=$size iterations=$it $(curl -sv "http://localhost/debug.php?size=$size&iterations=$it" 2>&1 | egrep '^< HTTP')"; done; done | grep 502 | head
size=121 iterations=30 < HTTP/1.1 502 Bad Gateway
size=109 iterations=33 < HTTP/1.1 502 Bad Gateway
size=232 iterations=33 < HTTP/1.1 502 Bad Gateway
size=241 iterations=48 < HTTP/1.1 502 Bad Gateway
size=145 iterations=51 < HTTP/1.1 502 Bad Gateway
size=226 iterations=51 < HTTP/1.1 502 Bad Gateway
size=190 iterations=60 < HTTP/1.1 502 Bad Gateway
size=115 iterations=63 < HTTP/1.1 502 Bad Gateway
size=109 iterations=66 < HTTP/1.1 502 Bad Gateway
size=163 iterations=69 < HTTP/1.1 502 Bad Gateway
[... there would be more here, but I piped through head ...]

fastcgi_buffers 16 16k; fastcgi_buffer_size 32k;:

bash-4.1# for it in {30..200..3}; do for size in {100..250..3}; do echo "size=$size iterations=$it $(curl -sv "http://localhost/debug.php?size=$size&iterations=$it" 2>&1 | egrep '^< HTTP')"; done; done | grep 502 | head
size=223 iterations=69 < HTTP/1.1 502 Bad Gateway
size=184 iterations=165 < HTTP/1.1 502 Bad Gateway
size=151 iterations=198 < HTTP/1.1 502 Bad Gateway
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment