Nginx 1.4.9 optimalization for digital hosting

Once you got everything installed in your system.

Start tuning it up.These are some useful information I manage to find.

1. /etc/nginx.conf optimalization.

worker_processes 1; Normally it’s a good idea to set this humber to a number of cores in your system

grep processor /proc/cpuinfo | wc -l (This will give you an idea of amount of cores)

worker_connections 1024; (This is a number of connection per core and a good starting point it to check your core limiation

$sudo ulimit -n (This will give a number which you can use in config)

In this configuration we can server 1024 connetion per/second so basically around 512 customers being live on website and making around 2 connection to server. If you website server few thousands visit a day this is more than enough!

and this is the final config



# cat /etc/nginx/nginx.conf 

user www-data;
worker_processes 1; # a number of cores on my VPS $grep processor /proc/cpuinfo | wc -l
pid /run/nginx.pid;

events {
	worker_connections 1024; # a number issued by runnig $ulimit -n (core limitation)
	# multi_accept on;
}

#A number of connection served by second is 1 * 1024  with current configuration
http {

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	types_hash_max_size 2048;
	include /etc/nginx/mime.types;
	default_type application/octet-stream;
    access_log off; # as i dont monitored them for now
	#access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;
	#passenger_root /usr;
	#passenger_ruby /usr/bin/ruby;

    client_body_buffer_size 10K; # sites form submissions
    client_header_buffer_size 1k; 
    client_max_body_size 8m; #a maximum allowed size for client request otherwise 413 code will be returned
    large_client_header_buffers 2 1k;
    client_body_timeout 12; #close the connection if client won't respond within 12s
    client_header_timeout 12; #as per above
    keepalive_timeout 15;
    send_timeout 10;
    
    #to reduce bandwith and speed up pages respond
    gzip             on;
    gzip_comp_level  2;
    gzip_disable "msie6";
    gzip_min_length  1000;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_types       text/plain application/x-javascript text/xml text/css application/xml;

	# Virtual Host Configs
	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}

This is just a starting point so it’s good setup to start of.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s