性能优化-优化Nginx连接参数,调整连接超时时间
worker_connections增加连接数,但不是意味着通过worker_connections增大了,就可以浪费,在一定程度上通过超时时间控制,可以有效的节省连接数,不会造成资源浪费,即开源了又节流了
keepalive_timeout 60;
确保通讯双方在一定时间内都没有数据传输了, 就断开连接
设置参数 keepalive_timeout 60; 作用:客户端连接在服务器端保持多久后退出
参数语法 keepalive_timeout 时间数(秒);
放置位置 http,server,location
client_header_timeout 15;
发送方放出请求信息, 但接收方迟迟不作出响应
设置参数 client_header_timeout 15; 作用:设置读取客户端请求头数据的超时时间,如果超过这个时间客户端还没有发送完整的数据,服务器端将返回408错误,放置客户端利用http协议进行***
参数语法 client_header_timeout 时间数(秒);
放置位置 http,server
client_body_timeout 15
发送方发出主体信息, 但接收方没有正常处理
设置参数 client_body_timeout 15; 作用:设置读取客户端请求主体的超时间
参数语法 client_body_timeout 时间数(秒);
放置位置 http,server,location
send_timeout 25;
服务端等待客户端两次请求的间隔时间
设置参数 send_timeout 25; 作用:设置服务端传送HTTP响应信息到客户端的超时间
参数语法 send_timeout 时间数(秒);
放置位置 http,server,location
配置以上参数
在主配置文件nginx.conf中配置
[root@web01 ~]# cat /application/nginx/conf/nginx.conf worker_processes 2; worker_cpu_affinity 0101 1010; error_log logs/error.log; #配置Nginx worker进程最大打开文件数 worker_rlimit_nofile 65535; user www www; events { #单个进程允许的客户端最大连接数 worker_connections 20480; #使用epoll模型 use epoll; } http { include mime.types; default_type application/octet-stream; #sendfile on; #keepalive_timeout 65; #访问日志配置 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; #虚拟主机 include /application/nginx/conf/extra/www.conf; include /application/nginx/conf/extra/blog.conf; include /application/nginx/conf/extra/bbs.conf; include /application/nginx/conf/extra/edu.conf; include /application/nginx/conf/extra/phpmyadmin.conf; include /application/nginx/conf/extra/status.conf; #nginx优化---------------------- #隐藏版本号 server_tokens on; #优化服务器域名的散列表大小 server_names_hash_bucket_size 64; server_names_hash_max_size 2048; #开启高效文件传输模式 sendfile on; #减少网络报文段数量 #tcp_nopush on; #提高I/O性能 tcp_nodelay on; #连接超时 时间定义 默认秒 默认65秒 keepalive_timeout 60; #读取客户端请求头数据的超时时间 默认秒 默认60秒 client_header_timeout 15; #读取客户端请求主体的超时时间 默认秒 默认60秒 client_body_timeout 15; #响应客户端的超时时间 默认秒 默认60秒 send_timeout 25; }
转载于:https://blog.51cto.com/13673885/2299770