a* nginx配置文件中worker_processes必须要和cpu核数一致(减少上下文切换);
- accept_mutex
- 默认打开:好处是解决惊群现象,简单理解为worker串行工作;
- 关闭:高并发,提高吞吐,可理解为worker并行工作;
- 事件驱动模型 epoll;
events {
use epoll; #epoll多路复用IO
worker_connections 1024; #单个后台worker process进程的最大并发链接数
multi_accept on; #nginx在已经得到一个新连接的通知时,接收尽可能多的连接
accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
}
- 排错:
- Nginx 502 Bad Gateway
netstat -anpo | grep "php-cgi" | wc -l #查看当前的PHP FastCGI进程数是否够用
- 部分PHP程序的执行时间超过了Nginx的等待时间,可以适当增加
http {
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
- upstream sent too big header while reading response header from upstream
- 如果是nginx反向代理
server { large_client_header_buffers 4 16k; location / { #添加这3行 proxy_buffer_size 64k; proxy_buffers 32 32k; proxy_busy_buffers_size 128k; } }
- 如果是 nginx+PHPcgi
fastcgi_buffer_size 128k; fastcgi_buffers 4 128k; server { client_header_buffer_size 128k; large_client_header_buffers 4 128k; proxy_buffer_size 64k; proxy_buffers 8 64k; fastcgi_buffer_size 128k; fastcgi_buffers 4 128k; location / { ...... } }