温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nginx timeout超时如何配置

发布时间:2022-06-02 11:45:32 来源:亿速云 阅读:239 作者:iii 栏目:大数据

本文小编为大家详细介绍“Nginx timeout超时如何配置”,内容详细,步骤清晰,细节处理妥当,希望这篇“Nginx timeout超时如何配置”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

keepalive_timeout

http 有一个 keepalive 模式,它告诉 webserver 在处理完一个请求后保持这个 tcp 连接的打开状态。若接收到来自客户端的其它请求,服务端会利用这个未被关闭的连接,而不需要再建立一个连接。

http keep-alive, 網頁的每一個請求都是http (圖片, css等), 而打開http 請求是要先建立tcp 連接, 而如果一個頁面每個請求都要打開及關閉一個tcp 連接就會做成資源的浪費. keepalive_timeout 就是當一個http 請求完成, 其tcp 連接會存留下來的時間, 如果這時有另一個http 請求過來, 會複用這個tcp 連接, 如果再沒有新的請求過來, 才會關閉其tcp連接

user nginx;
worker_processes 1;
 
error_log /var/log/nginx/error.log warn;
pid    /var/run/nginx.pid;
 
 
events {
  worker_connections 1024;
}
 
 
http {
  include    /etc/nginx/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 /var/log/nginx/access.log main;
 
  sendfile    on;
  tcp_nopush   on;
  tcp_nodelay on;
 
 
  keepalive_timeout 65;
  client_max_body_size 8192m;
 
  #gzip on;
 
  #include /etc/nginx/conf.d/*.conf;
 
 
 
  server {
 listen 80 so_keepalive=30m::;
 listen 443 default ssl;
 
 ssl_certificate /etc/nginx/ssl/server.crt;
 ssl_certificate_key /etc/nginx/ssl/portalkey.key;
 #ssl_password_file /etc/nginx/ssl/ssl.pass;
 
 
    ssl_session_timeout 5m;
    ssl_protocols sslv2 sslv3 tlsv1;
    ssl_ciphers high:!anull:!md5;
    ssl_prefer_server_ciphers on;
 
 location / {
 proxy_request_buffering off;
 proxy_pass http://127.0.0.1:8011/;
 proxy_connect_timeout    180;
    proxy_send_timeout     180;
    proxy_read_timeout     180;
    send_timeout  180;
 }
 location /test1_url/ {
 proxy_pass http://127.0.0.1:8008/;
 proxy_connect_timeout    180;
    proxy_send_timeout     180;
    proxy_read_timeout     180;
    send_timeout  180;
 }
 location /test2_url/ {
 proxy_pass http://127.0.0.1:3000/;
 proxy_connect_timeout    180;
    proxy_send_timeout     180;
    proxy_read_timeout     180;
    send_timeout  180;
 }
  }
}

# 配置段: http,默认75s

keepalive_timeout 60;

  • send_timeout :发送数据至客户端超时, 默认60s, 如果连续的60s内客户端没有收到1个字节, 连接关闭

  • proxy_connect_timeout: nginx与upstream server的连接超时时间

  • proxy_read_timeout: nginx接收upstream server数据超时, 默认60s, 如果连续的60s内没有收到1个字节, 连接关闭

  • proxy_send_timeout: nginx发送数据至upstream server超时, 默认60s, 如果连续的60s内没有发送1个字节, 连接关闭

so_timeout:

當用戶跟server開啟了tcp connection --> 一段長時間這個connection 沒traffic (so_keepalive timeout) --> server 發出探測包看用戶是否還存在 --> 若探測包沒回, 則關閉tcp connection 

so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]
so_keepalive=30m::10
  will set the idle timeout (tcp_keepidle) to 30 minutes, leave the probe interval (tcp_keepintvl) at its system default, and set the probes count (tcp_keepcnt) to 10 probes.

以上三个参数只能使用一个,不能同时使用, 比如so_keepalive=on, so_keepalive=off或者so_keepalive=30s::(表示等待30s没有数据报文发送探测报文)

读到这里,这篇“Nginx timeout超时如何配置”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI