Optimize Nginx For High Traffic

Optimize Nginx For High Traffic
Optimize Nginx For High Traffic

 

Optimize Nginx For High Traffic

I assume you have 4GB Ram, 8 Cores CPU and Storage dosen’t matter, let’s talk about you have 50K traffic everyday to your VPS and let’s tweak to accept more. If you have Ram of 1GB and 2 Core CPU and have traffic 20K to 30K per day then you can use the same tweak just use worker_processes as 2, worker_connections 25000 and worker_rlimit_nofile 25000

locate nginx.conf (/etc/nginx/nginx.conf) and edit OR add as following

user www-data;
worker_processes 4; (This tweak belongs to your CPU Cores, you can increase more if like to, recommended is 4)
worker_rlimit_nofile 50000;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 50000;
multi_accept on;
use epoll;
}

# Total users can serve = worker_processes * worker_connections

http {
include /etc/nginx/mime.types;

access_log /var/log/nginx/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65; (Default is 0)
reset_timedout_connection on;
types_hash_max_size 2048;
tcp_nodelay on;

client_max_body_size 10M; (This also means max php upload size and can conflict with PHP.INI max_upload_size)
client_body_buffer_size 32k;
client_body_in_single_buffer on;
client_body_timeout 180s;
client_header_timeout 180s;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k; (worker_processes * no of large_client_header_buffers)

gzip on;
gzip_buffers 16 8k;
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server_names_hash_bucket_size 128;
}

After editing the file restart nginx by simply service nginx restart (command is depends on your OS), recommended is to restart VPS and enjoy the high traffic website. I also used W3 Total Cache Plugin and tweak patch with Nginx, to know more about that check my other article which covers entire section about Nginx + WordPress + W3 Total Cache + High Traffic

Feel free to ask me your queries if any about Optimize Nginx For High Traffic

 Subscribe to Newsletter to receive Updates about the Latest Blog Content

Summary
Optimize Nginx For High Traffic
Article Name
Optimize Nginx For High Traffic
Description
Nginx gives blazing performance for WordPress, Joomla, Magneto and other CMS, Ecommerce Applications. Nginx works lighting fast over wordpress and gives stability, i never faced issues of 404 Bad Gateway with Nginx due to high traffic.
Author

One thought on “Optimize Nginx For High Traffic

Leave a Reply

Your email address will not be published. Required fields are marked *