Tweaking Nginx proxy_buffers parameters

May 06, 2022 · 1 min read · Post a comment
Tweaking Nginx proxy_buffers parameters

Before setting up YOLO values for proxy_buffers and proxy_buffer_size parameters, you need to find out the average and maximum response sizes first. On a side note, the following steps (as shown below) will apply to fastcgi_buffers as well, although these two represent different scenarios.

Generally speaking proxy_buffers are used in proxy (reverse) mode, so Nginx sits in front of apps, web servers, Docker and what not. On the other hand, fastcgi_buffers comes into play mostly when serving PHP apps by proxying to php-fpm for instance. Sometimes you may end up using them both.


  • Nginx

Get average response size

echo $(( `awk '($9 ~ /200/)' /var/log/nginx/access.log | awk '{print $10}' | awk '{s+=$1} END {print s}'` / `awk '($9 ~ /200/)' /var/log/nginx/access.log  | wc -l` ))

Average response size in Bytes for


Get maximum response size

cat /var/log/nginx/access.log | grep "200" | awk '{print $10}' | sort -nr | head -n 1

Maximum response size in Bytes for


Optimization example

Step 1. Get the current proxy_buffers and proxy_buffer_size parameter values determined by the default memory page size.

getconf PAGESIZE

Example output:


Step 2. Since the average response rate is 40k, and the maximum response rate is around 1MB, 4k won’t do enough. So, the optimal proxy_buffer values would be:

proxy_buffers 4 64k;
proxy_buffer_size 64k;

Step 3. Reload Nginx.

sudo systemctl reload nginx


Inspired by Tweaking fastcgi-buffers.
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.