<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Nginx :: Tag :: Ay Docs</title>
    <link>https://ops.docs.72602.space/tags/nginx/index.html</link>
    <description></description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Mon, 07 Oct 2024 19:58:45 +0800</lastBuildDate>
    <atom:link href="https://ops.docs.72602.space/tags/nginx/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Nginx 性能优化</title>
      <link>https://ops.docs.72602.space/using/networking/nginx/index.html</link>
      <pubDate>Mon, 07 Oct 2024 19:58:45 +0800</pubDate>
      <guid>https://ops.docs.72602.space/using/networking/nginx/index.html</guid>
      <description>从通用优化、操作系统层、Nginx 配置层、架构层等多个维度，为你详细梳理的方式。&#xA;一、操作系统与硬件层优化 这是优化的基础，为 Nginx 提供一个高性能的运行环境。&#xA;增加文件描述符限制 Nginx 每个连接（尤其是静态文件）都会消耗一个文件描述符。如果并发高，默认限制很容易成为瓶颈。&#xA;# 临时生效 ulimit -n 65536 # 永久生效，修改 /etc/security/limits.conf * soft nofile 65536 * hard nofile 65536 # 同时，确保 nginx.conf 中使用了足够的 worker_rlimit_nofile worker_rlimit_nofile 65536; 优化网络栈&#xA;调整 net.core.somaxconn： 定义等待 Nginx 接受的最大连接队列长度。如果遇到 accept() 队列溢出的错误，需要增加这个值。 sysctl -w net.core.somaxconn=65535 并在 Nginx 的 listen 指令中显式指定 backlog 参数： listen 80 backlog=65535; 启用 TCP Fast Open： 减少 TCP 三次握手的延迟。 sysctl -w net.ipv4.tcp_fastopen=3 增大临时端口范围： 当 Nginx 作为反向代理时，它需要大量本地端口来连接上游服务器。 sysctl -w net.ipv4.ip_local_port_range=&#34;1024 65535&#34; 减少 TCP TIME_WAIT 状态： 对于高并发短连接场景，大量连接处于 TIME_WAIT 状态会耗尽端口资源。 # 启用 TIME_WAIT 复用 sysctl -w net.ipv4.tcp_tw_reuse=1 # 快速回收 TIME_WAIT 连接 sysctl -w net.ipv4.tcp_tw_recycle=0 # 注意：在 NAT 环境下建议为 0，否则可能有问题 # 增大 FIN_WAIT_2 状态的超时时间 sysctl -w net.ipv4.tcp_fin_timeout=30 使用高性能磁盘 对于静态资源服务，使用 SSD 硬盘可以极大提升 IO 性能。</description>
    </item>
  </channel>
</rss>