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.
Prerequisites
- 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 devcoops.com:
40429
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 devcoops.com:
1040722
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:
4096
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
Conclusion
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.