美文网首页nginx365日更挑战
日更第9日: (翻)nginx调优之upstream开启keep

日更第9日: (翻)nginx调优之upstream开启keep

作者: 微凉哇 | 来源:发表于2021-10-21 12:19 被阅读0次

    upstream开启keepalive

    原文地址

    解释说明

    配置keepalive的主要意图:解决在高延迟网络上建立TCP连接的延迟问题。
    nginx与上游服务器之间需要持续保持一定数量的连接时,keepalive很有用。

    开启Keep-Alive连接对性能有很大的影响:减少了打开和关闭连接所需的CPU和网络开销。

    通过在nginx中启用HTTP keepalive,降低了nginx连接上游服务器的延迟,从而提高了性能,并减少了nginx耗尽临时端口的可能性。
    nginx将重用现有的TCP连接,而不创建新的TCP,
    这可以极大地减少繁忙服务器上TIME_WAIT TCP连接中的套接字数量(减少操作系统建立新连接的工作,减少网络上的数据包)

    注意: 仅在HTTP/1.1时支持Keep-Alive连接。

    配置样例

    # Upstream context:
    upstream backend {
    
      # Sets the maximum number of idle keepalive connections to upstream servers
      # that are preserved in the cache of each worker process.
      keepalive 16;
    
    }
    
    # Server/location contexts:
    server {
    
      ...
    
      location / {
    
        # By default only talks HTTP/1 to the upstream,
        # keepalive is only enabled in HTTP/1.1:
        proxy_http_version 1.1;
    
        # Remove the Connection header if the client sends it,
        # it could be "close" to close a keepalive connection:
        proxy_set_header Connection "";
    
        ...
    
      }
    
    }
    

    相关文章

      网友评论

        本文标题:日更第9日: (翻)nginx调优之upstream开启keep

        本文链接:https://www.haomeiwen.com/subject/wnxboltx.html