Skip to content Skip to sidebar Skip to footer

Optimizing Nginx For Better Performance

When i am in internship, i tried to figure out how to make Nginx work as efficient as possible. In this article, i will explain how Nginx serving request from client and how to make available resource distributed efficiently to prevent creating process that may cause a problem to the server itself.

To configure Nginx, we need to know that there are two component that will help controlling hardware to execute request from client. They are worker process and worker connection. The easy explanation is, worker Process are used to control and distribute job (request from client) to worker connection, and the worker connection are the slave that actually do the job. Worker process will use the physical core of your server's processor to distribute the job to worker connection. Worker connection is a slave of worker processor who defines maximum connection that can be established to the server. connection here means a user that accessing website through their PC computer. As default, one core used by worker process can handle 768 connection, and one tab of the browser that opening the website mostly require 2 connection. By default, 768 connection can serve 384 tabs of browser.

If you willing to manually configure that settings, you need to know the detailed specification of server especially the processor's core. Here's the command to make sure how many cores you have on your server.


The "20" that appear are the number of cores you have on current server. Next step is to know the maximum connection that you can handle per core by typing these command


The "1024" are the maximum connection that server can handle. 

Now you can customise your own configuration by calculating your needs. For example, there are 27 user that accessing the server everyday, which every user are mostly opening 10 tab browser to accessing the website. In that case, we can calculate 27 Users x ( 10 browser tabs x 2 worker connection) = 540 connection. We at least must have 540 connection so we can handle the request from user, and let's just leave the worker connection by default number (1024 connection) because with 1024 connection, we still have 484 connection available as spare in server.

Now, all we need to do is just open configuration in /etc/nginx.conf file. by typing nano /etc/nginx.conf and edit those configuration as picture below


later on, restart nginx by typing service nginx restart.

To see how much connection are established from user to your server, you can type in these command below. Here, 4 are appear as how much connection are established and IP address are the address of the client computer (user)