Boost Nginx and PHP FPM performance with expert tuning tips. Get reliable optimisation from our Nginx Support team.

Nginx and PHP FPM Tuning Guide for High Traffic Performance

If you are searching for how to optimise Nginx and PHP FPM for production traffic, focus on configuration first. Defaults are safe, not fast. Below are production ready snippets you can review, adjust, and deploy.

Nginx and PHP FPM Tuning Guide for High Traffic PerformanceNginx and PHP FPM Tuning Guide for High Traffic Performance

Worker and Connection Limits

Set concurrency correctly before tuning anything else.

worker_processes auto;
worker_connections 1024;
multi_accept on;

Increase OS limits accordingly
ulimit -n 65535

Timeout Configuration

Prevent slow clients from blocking workers.

client_header_timeout 10s;
client_body_timeout   10s;
send_timeout          10s;
keepalive_timeout     15s;
fastcgi_connect_timeout 5s;
fastcgi_send_timeout    30s;
fastcgi_read_timeout    60s;

Match FastCGI values with PHP max execution time.

Get Expert Support Now

Chat animation


Gzip Compression

Enable compression to reduce payload size.

gzip on;
gzip_vary on;
gzip_min_length 1024;

gzip_types text/plain text/css application/json application/javascript text/xml application/xml+rss text/javascript;

Buffer Configuration

Control memory usage and request handling.

client_body_buffer_size 15k;
client_header_buffer_size 2k;
client_max_body_size 8m;
large_client_header_buffers 4 4k;

Increase header buffers only if your application uses large cookies or tokens.

File Cache Optimisation

Reduce disk I O overhead.

open_file_cache max=2000 inactive=20s;
open_file_cache_valid 60s;
open_file_cache_min_uses 5;
open_file_cache_errors off;

Static Asset Caching

Avoid repeated backend hits.

location /static/ {
root /var/www/site;
expires max;
add_header Cache-Control "public, immutable";
}

Use versioned file names during deployment.

FastCGI Cache for Dynamic Content

Bypass cache when needed.

set $skip_cache 0;
if ($request_method = POST) { set $skip_cache 1; }
if ($query_string != "")   { set $skip_cache 1; }
if ($http_cookie ~* "session|logged_in") { set $skip_cache 1; }

Cache configuration
fastcgi_cache_path /var/cache/nginx/php levels=1:2 keys_zone=phpcache:100m inactive=60m max_size=1g;

location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_cache phpcache;
fastcgi_cache_valid 200 301 302 10m;
fastcgi_cache_valid 404 1m;
fastcgi_cache_use_stale error timeout updating;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache     $skip_cache;
}

PHP FPM Production Pool

Tune process management based on memory capacity.

pm = dynamic
pm.max_children = 100
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 30
pm.max_requests = 500
request_terminate_timeout = 120s
request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm/slow.log
rlimit_files = 65536
listen.backlog = 8192
catch_workers_output = yes
php_admin_value[opcache.enable] = 1
php_admin_value[opcache.memory_consumption] = 256
php_admin_value[opcache.interned_strings_buffer] = 32
php_admin_value[opcache.max_accelerated_files] = 100000
php_admin_value[opcache.validate_timestamps] = 0

Calculate max children using available RAM divided by average PHP process size.

ECC SSL Key Generation

Reduce handshake overhead under HTTPS load.

openssl ecparam -out ./nginx-ecc-p256.key -name prime256v1 -genkey
openssl req -new -key ./nginx-ecc-p256.key -out ./nginx-ecc-p256-csr.pem -subj '/CN=localhost'
openssl req -x509 -nodes -days 30 -key ./nginx-ecc-p256.key -in ./nginx-ecc-p256-csr.pem -out ./nginx-ecc-p256.pem

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Real performance comes from precise configuration, not bigger hardware. Review your current setup, apply the relevant tuning blocks, and validate results with load testing.

If you are preparing for higher traffic, start implementing these changes now and download the complete optimisation checklist to harden your production stack.