涛哥在用swoole进行压力测试时,在nginx的error.log发现了一些警报,诸如:
1 2 |
2020/04/25 12:08:32 [alert] 20768#0: *137363 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: www.kydbk-admin.com, request: "GET /api/user HTTP/1.1", upstream: "http://127.0.0.1:1215/api/user", host: "www.kydbk-admin.com" 2020/04/25 12:08:32 [alert] 20768#0: *137439 setsockopt(TCP_NODELAY) failed (22: Invalid argument) while keepalive, client: 127.0.0.1, server: 0.0.0.0:80 |
这是因为访问量的增大,相应nginx连接数,以及打开的文件数,nginx.conf是需要调整的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#涛哥的mac上nginx 1.17.10配置 #user nobody; worker_processes auto; #定义了nginx对外提供web服务时的worker进程数。最优值取决于许多因素,包括(但不限于)CPU核的数量、存储数据的硬盘数量及负载模式。不能确定的时候,将其设置为可用的CPU内核数将是一个好的开始(设置为“auto”将尝试自动检测它) worker_rlimit_nofile 65535; #更改worker进程的最大打开文件数限制。如果没设置的话,这个值为操作系统的限制。设置后你的操作系统和Nginx可以处理比“ulimit -a”更多的文件,所以把这个值设高,这样nginx就不会有“too many open files”问题了 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { use kqueue; #use 设置用于复用客户端线程的轮询方法。如果你使用Linux 2.6+,你应该使用epoll。如果你使用BSD如mac,你应该使用kqueue。 multi_accept on; #告诉nginx收到一个新连接通知后接受尽可能多的连接 worker_connections 65535; #设置可由一个worker进程同时打开的最大连接数 } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #用户优化静态文件 tcp_nopush on; #让nginx在一个数据包中发送所有的头文件,而不是一个一个单独发 server_tokens off; #可以关闭在错误页面中的nginx版本数字,这样对于安全性是有好处的 #keepalive_timeout 0; keepalive_timeout 65; |
更多nginx优化
nginx反向代理 https://blog.csdn.net/qq_42030417/article/details/83185809
高并发之 Nginx 优化 http://lzly216.com/article/nginx_high
nginx转发swoole以及nginx负载 https://www.cnblogs.com/phpshen/p/9166104.html
Nginx性能优化指南 https://www.linuxidc.com/Linux/2015-10/124365.htm
仔细看参数–NGINX之tcp_nodelay https://www.cnblogs.com/MrVolleyball/p/10972166.html
Nginx 作为反向代理优化要点proxy_buffering https://blog.csdn.net/cymm_liu/article/details/76667153
Nginx反向代理+Nginx性能优化配置详解 https://blog.csdn.net/Kangshuo2471781030/article/details/79194973
更多待涛哥实践总结…
转载请注明:PHP笔记 » nginx反向代理swoole配置性能优化