1.nginx相对与linux内核优化
net.core.netdev_max_backlog = 262114
net.core.somaxconn = 262114
net.ipv4.tcp_max_orphans = 262114
net.ipv4.tcp_max_syn_backlog = 262114
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
2.针对Cpu的Nginx配置优化
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
3.针对网络配置优化
keepalive_timeout 60 50;
send_timeout 10s;
client_header_buffer_size 16k;
4.跟事件驱动有关的
use epoll;
worker_connections 65535;
worker_rlimit_nofile 1024;
5.Gzip压缩
gzip on;
gzip_buffers 32 4k | 64 8k;
gzip_comp_level 4;
gzip_min_length 1024;
gzip_vary on;
gzip_types text/css text/xml application/javascript;
gunzip_static on;
gzip_disable "MSIE [1-6]\.";
6.Nginx后端服务器组配置
upstream backend {
server 127.0.0.1:9501 weight=65;
server 127.0.0.1:9502 weight=105;
server 127.0.0.1:9503 weight=45;
server 127.0.0.1:9504 weight=85;
}
server {
listen 9500;
server_name 127.0.0.1;
location / {
proxy_pass http://backend;
}
}
net.core.netdev_max_backlog = 262114
net.core.somaxconn = 262114
net.ipv4.tcp_max_orphans = 262114
net.ipv4.tcp_max_syn_backlog = 262114
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
2.针对Cpu的Nginx配置优化
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
3.针对网络配置优化
keepalive_timeout 60 50;
send_timeout 10s;
client_header_buffer_size 16k;
4.跟事件驱动有关的
use epoll;
worker_connections 65535;
worker_rlimit_nofile 1024;
5.Gzip压缩
gzip on;
gzip_buffers 32 4k | 64 8k;
gzip_comp_level 4;
gzip_min_length 1024;
gzip_vary on;
gzip_types text/css text/xml application/javascript;
gunzip_static on;
gzip_disable "MSIE [1-6]\.";
6.Nginx后端服务器组配置
upstream backend {
server 127.0.0.1:9501 weight=65;
server 127.0.0.1:9502 weight=105;
server 127.0.0.1:9503 weight=45;
server 127.0.0.1:9504 weight=85;
}
server {
listen 9500;
server_name 127.0.0.1;
location / {
proxy_pass http://backend;
}
}