Tuning the Nginx Configuration
Adjust Nginx parameters to improve the Nginx performance.
The default Nginx configuration file is nginx.conf, which is located in the Nginx installation directory by default. The following is an example of an optimized Nginx configuration file.
The example configuration file is for reference only. In actual situations, adjust the configuration file based on your actual hardware environment and service requirements.
user root;
worker_processes auto; # Detect and set the number of worker processes automatically.
events {
worker_connections 102400; # Increase the maximum number of connections of each working process.
multi_accept on; # Accept multiple network connections at the same time.
use epoll; # Use the epoll event model.
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on; # Enable the efficient file transfer mode.
keepalive_timeout 65s; # Set the timeout interval for persistent connections.
server {
listen 10000;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 20000 ssl;
server_name localhost;
ssl_certificate /usr/local/nginx/server_2048.crt;
ssl_certificate_key /usr/local/nginx/server_2048.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
gzip on; # Enable Gzip compression.
gzip_buffers 4 16k; # Configure the Gzip compression buffer.
gzip_comp_level 9; # Set the Gzip compression level (the highest level is 9).
gzip_disable "MSIE [1-6]\."; # Disable Gzip compression for old Internet Explorer versions.
gzip_http_version 1.1; # Require the client to support HTTP 1.1 or later to enable Gzip compression.
gzip_min_length 500k; # Set the minimum size of a file that uses Gzip compression.
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml; # Specify the files of MIME type to be compressed using Gzip.
gzip_vary on; # Add Vary: Accept-Encoding to the response header to process the proxy cache.
keepalive_requests 20000; # Set the maximum number of requests for each persistent connection.
open_file_cache max=102400 inactive=40s;
open_file_cache_errors on;
open_file_cache_min_uses 1;
open_file_cache_valid 50s;
proxy_buffer_size 1024k;
proxy_buffers 16 1024k;
proxy_busy_buffers_size 2048k;
proxy_temp_file_write_size 2048k;
sendfile_max_chunk 512k; # Set the maximum data block size of sendfile.
tcp_nodelay on; # Enable the TCP_NODELAY option.
tcp_nopush on; # Enable the TCP_NOPUSH option (to improve performance in some scenarios).
access_log off; #Disable the access_log log function.
}
Parent topic: Nginx Performance Tuning