LNMP并发处理的核心思路
关键配置与落地参数
并发瓶颈定位与优化顺序
快速配置示例
worker_processes auto;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 10240;
}
http {
keepalive_timeout 65;
keepalive_requests 100;
gzip on;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
add_header Cache-Control "public";
}
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=60m use_temp_path=off;
upstream backend {
server 10.0.0.11:9000;
server 10.0.0.12:9000;
server 10.0.0.13:9000;
}
server {
location / {
proxy_cache my_cache;
proxy_pass http://backend;
}
}
[www]
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
ulimit -n 65535
sysctl -w net.core.somaxconn=65535
sysctl -w net.ipv4.tcp_max_syn_backlog=65535
sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -w net.ipv4.tcp_tw_reuse=1
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
wrk -t4 -c100 -d60s --latency http://your-domain/index.php