How to configure Nginx to optimize performance

Tutorials 0 lượt xem

Nginx is a lightweight web server and has better performance than Apache 2. 

However, like other software, you still have to have a few customizations if you want to get optimal performance.

Today we will learn how to configure Nginx for optimal performance.

Specifically, we will modify the configuration file /etc/nginx/nginx.conf . ​

Before changing, please back up the file for safety: ​


cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup

​Remember to run the following command every time you change Nginx configuration

systemctl restart nginx

Note: the article references these articles and this article

Worker_processes and worker_connection

Worker_processes is the maximum total number of processes that Nginx uses. Usually 1 worker processes per CPU core. You can use the following command to check the number of cores: 

grep processor /proc/cpuinfo | wc -l

Use this number for worker processes. 

Worker connections ​indicates how many people Nginx can serve simultaneously. You can check the processor limit with the following command: 

ulimit -n

Use this number for worker_connections. 

Buffer size

Insert this paragraph in the http​​​​​ pair

client_body_buffer_size 128k;
client_max_body_size 10m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
output_buffers 1 32k;
postpone_output 1460;

Enable Gzip

Insert this paragraph in the http​​​​​ pair

gzip on;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
gzip_static on;
gzip_min_length 1400;
gzip_buffers 32 8k;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_proxied any;
gzip_types text/plain text/css text/xml application/javascript application/x-javascript application/xml application/xml+rss application/ecmascript application/json image/svg+xml;

Just a few basic configuration steps as above will help Nginx work with good performance. 

View articles in the series

Previous part: LEMP for Centos 7: Adding a website for NGINX Next part: How to install WordPress on CentOS 7

Bài viết liên quan