[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"knowledge-\u002Fapi\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Fpre":3,"knowledge-related-\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Fpre":987,"knowledge-series-\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Fpre":1013},{"source":4,"connector":5,"page":6},"sqlite","better-sqlite3",{"path":7,"title":8,"description":9,"category":10,"tags":11,"date":14,"pinned":15,"draft":15,"body":16,"seo":983,"stem":984,"id":985,"extension":986},"\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Fpre","性能调优基础","性能调优的目标是：用有限的资源，支撑更高的并发、更快的响应、更稳的服务。下面按优化维度，逐一拆解原理和配置要诀。","技能小册",[12,13],"nginx","pre","2020-07-11",false,{"type":17,"value":18,"toc":975},"minimark",[19,22,31,36,41,50,55,96,103,111,118,123,142,148,152,156,171,175,205,224,233,237,244,264,268,367,370,374,388,392,422,426,454,459,463,470,474,574,592,596,607,614,618,666,686,693,700,705,793,819,823,826,851,861,866,919,922,926,971],[20,21,8],"h1",{"id":8},[23,24,25,26,30],"p",{},"性能调优的目标是：",[27,28,29],"strong",{},"用有限的资源，支撑更高的并发、更快的响应、更稳的服务","。下面按优化维度，逐一拆解原理和配置要诀。",[32,33,35],"h3",{"id":34},"一工作进程优化","一、工作进程优化",[37,38,40],"h4",{"id":39},"_1-worker-数量","1. Worker 数量",[23,42,43,46,49],{},[27,44,45],{},"原理",[47,48],"br",{},"\n每个 Worker 是一个单线程事件循环，绑定到一个 CPU 核心上可以避免上下文切换和 CPU 缓存失效。Worker 数量超过核心数会引起争抢，小于核心数则不能充分利用多核能力。",[23,51,52],{},[27,53,54],{},"配置",[13,56,60],{"className":57,"code":58,"language":12,"meta":59,"style":59},"language-nginx shiki shiki-themes material-theme-lighter github-light github-dark","# 推荐自动匹配\nworker_processes auto;\n\n# 亦可手动指定，如 4 核机器\nworker_processes 4;\n","",[61,62,63,71,77,84,90],"code",{"__ignoreMap":59},[64,65,68],"span",{"class":66,"line":67},"line",1,[64,69,70],{},"# 推荐自动匹配\n",[64,72,74],{"class":66,"line":73},2,[64,75,76],{},"worker_processes auto;\n",[64,78,80],{"class":66,"line":79},3,[64,81,83],{"emptyLinePlaceholder":82},true,"\n",[64,85,87],{"class":66,"line":86},4,[64,88,89],{},"# 亦可手动指定，如 4 核机器\n",[64,91,93],{"class":66,"line":92},5,[64,94,95],{},"worker_processes 4;\n",[23,97,98,99,102],{},"可查看 ",[61,100,101],{},"\u002Fproc\u002Fcpuinfo"," 确认物理核心数，一般无需超过该值（除非存在大量阻塞 I\u002FO，但 Nginx 设计初衷就是非阻塞，极少需要超配）。",[37,104,106,107,110],{"id":105},"_2-cpu-亲和性worker_cpu_affinity","2. CPU 亲和性（",[61,108,109],{},"worker_cpu_affinity","）",[23,112,113,115,117],{},[27,114,45],{},[47,116],{},"\n将每个 Worker 进程绑定到指定的 CPU 核心，减少进程在不同核心间迁移导致的缓存失效，并提高 CPU 利用率。注意，现代调度器通常做得足够好，此配置已非必需，但在高负载实时系统或特殊 NUMA 环境下可能仍有收益。",[23,119,120],{},[27,121,122],{},"配置示例",[13,124,126],{"className":57,"code":125,"language":12,"meta":59,"style":59},"worker_processes 4;\n# 四核心，一 Worker 绑定一核心\nworker_cpu_affinity 0001 0010 0100 1000;\n",[61,127,128,132,137],{"__ignoreMap":59},[64,129,130],{"class":66,"line":67},[64,131,95],{},[64,133,134],{"class":66,"line":73},[64,135,136],{},"# 四核心，一 Worker 绑定一核心\n",[64,138,139],{"class":66,"line":79},[64,140,141],{},"worker_cpu_affinity 0001 0010 0100 1000;\n",[23,143,144],{},[145,146,147],"em",{},"如无明确测试依据，使用默认（不绑定）即可。",[32,149,151],{"id":150},"二连接与超时微调","二、连接与超时微调",[37,153,155],{"id":154},"_1-最大并发与连接数","1. 最大并发与连接数",[23,157,158,160,162,163,166,167,170],{},[27,159,45],{},[47,161],{},"\n每个 Worker 能打开的文件描述符数受系统限制（",[61,164,165],{},"ulimit -n","），Nginx 最大并发连接数 ≈ ",[61,168,169],{},"worker_processes × worker_connections","。但每个客户端会占用 2 个左右连接（如正向代理），且系统还要保留文件描述符给静态文件、日志等，需留有余量。",[23,172,173],{},[27,174,54],{},[13,176,178],{"className":57,"code":177,"language":12,"meta":59,"style":59},"events {\n    worker_connections  4096;\n    # 控制同时接受多个新连接\n    multi_accept on;\n}\n",[61,179,180,185,190,195,200],{"__ignoreMap":59},[64,181,182],{"class":66,"line":67},[64,183,184],{},"events {\n",[64,186,187],{"class":66,"line":73},[64,188,189],{},"    worker_connections  4096;\n",[64,191,192],{"class":66,"line":79},[64,193,194],{},"    # 控制同时接受多个新连接\n",[64,196,197],{"class":66,"line":86},[64,198,199],{},"    multi_accept on;\n",[64,201,202],{"class":66,"line":92},[64,203,204],{},"}\n",[23,206,207,208,211,212,215,216,219,220,223],{},"同时要修改系统限制：编辑 ",[61,209,210],{},"\u002Fetc\u002Fsecurity\u002Flimits.conf"," 增加 ",[61,213,214],{},"nginx soft nofile 65535","，并确保 ",[61,217,218],{},"nginx.conf"," 中 ",[61,221,222],{},"worker_rlimit_nofile"," 设置为同等或更高：",[13,225,227],{"className":57,"code":226,"language":12,"meta":59,"style":59},"worker_rlimit_nofile 65535;\n",[61,228,229],{"__ignoreMap":59},[64,230,231],{"class":66,"line":67},[64,232,226],{},[37,234,236],{"id":235},"_2-keepalive-参数","2. Keepalive 参数",[23,238,239,241,243],{},[27,240,45],{},[47,242],{},"\nHTTP 长连接能复用 TCP 连接，减少握手开销，提升前端访问和后端代理的性能。",[245,246,247,256],"ul",{},[248,249,250,255],"li",{},[27,251,252],{},[61,253,254],{},"keepalive_timeout","：服务器端保持连接的超时，过长会堆积空闲连接消耗资源。",[248,257,258,263],{},[27,259,260],{},[61,261,262],{},"keepalive_requests","：单连接上允许的最大请求数，超过后关闭连接，以均衡连接复用与资源释放。",[23,265,266],{},[27,267,54],{},[13,269,271],{"className":57,"code":270,"language":12,"meta":59,"style":59},"http {\n    keepalive_timeout 60 60;   # 长连接 60 秒\n    keepalive_requests 1000;   # 单个连接最多服务1000个请求\n\n    # 对上游的长连接（反向代理时尤为重要）\n    upstream backend {\n        server 10.0.0.1:80;\n        keepalive 32;          # 保留的空闲 keepalive 连接数\n    }\n    server {\n        location \u002F {\n            proxy_http_version 1.1;\n            proxy_set_header Connection \"\";  # 清除 Connection 头以启用 keepalive\n            proxy_pass http:\u002F\u002Fbackend;\n        }\n    }\n}\n",[61,272,273,278,283,288,292,297,303,309,315,321,327,333,339,345,351,357,362],{"__ignoreMap":59},[64,274,275],{"class":66,"line":67},[64,276,277],{},"http {\n",[64,279,280],{"class":66,"line":73},[64,281,282],{},"    keepalive_timeout 60 60;   # 长连接 60 秒\n",[64,284,285],{"class":66,"line":79},[64,286,287],{},"    keepalive_requests 1000;   # 单个连接最多服务1000个请求\n",[64,289,290],{"class":66,"line":86},[64,291,83],{"emptyLinePlaceholder":82},[64,293,294],{"class":66,"line":92},[64,295,296],{},"    # 对上游的长连接（反向代理时尤为重要）\n",[64,298,300],{"class":66,"line":299},6,[64,301,302],{},"    upstream backend {\n",[64,304,306],{"class":66,"line":305},7,[64,307,308],{},"        server 10.0.0.1:80;\n",[64,310,312],{"class":66,"line":311},8,[64,313,314],{},"        keepalive 32;          # 保留的空闲 keepalive 连接数\n",[64,316,318],{"class":66,"line":317},9,[64,319,320],{},"    }\n",[64,322,324],{"class":66,"line":323},10,[64,325,326],{},"    server {\n",[64,328,330],{"class":66,"line":329},11,[64,331,332],{},"        location \u002F {\n",[64,334,336],{"class":66,"line":335},12,[64,337,338],{},"            proxy_http_version 1.1;\n",[64,340,342],{"class":66,"line":341},13,[64,343,344],{},"            proxy_set_header Connection \"\";  # 清除 Connection 头以启用 keepalive\n",[64,346,348],{"class":66,"line":347},14,[64,349,350],{},"            proxy_pass http:\u002F\u002Fbackend;\n",[64,352,354],{"class":66,"line":353},15,[64,355,356],{},"        }\n",[64,358,360],{"class":66,"line":359},16,[64,361,320],{},[64,363,365],{"class":66,"line":364},17,[64,366,204],{},[23,368,369],{},"开启上游 keepalive 可显著减少与后端的 TCP 握手和 TIME_WAIT，大幅提升代理能力。",[32,371,373],{"id":372},"三高效传输","三、高效传输",[37,375,377,378,381,382,381,385],{"id":376},"_1-sendfiletcp_nopushtcp_nodelay","1. ",[61,379,380],{},"sendfile","、",[61,383,384],{},"tcp_nopush",[61,386,387],{},"tcp_nodelay",[23,389,390],{},[27,391,45],{},[245,393,394,405,415],{},[248,395,396,400,401,404],{},[27,397,398],{},[61,399,380],{},"：调用 ",[61,402,403],{},"sendfile()"," 系统调用，将文件数据直接从内核缓冲区拷贝到网络栈，绕过用户态，实现零拷贝，极大提升静态文件传输效率。",[248,406,407,411,412,414],{},[27,408,409],{},[61,410,384],{},"：在开启 ",[61,413,380],{}," 后生效，将 HTTP 响应头与数据包合并发送，减少 TCP 分段，提升网络利用率。适合大文件。",[248,416,417,421],{},[27,418,419],{},[61,420,387],{},"：关闭 Nagle 算法，让小包立即发送，不等待合并，减少延迟。适合需要实时交互的请求（如 API、WebSocket）。",[23,423,424],{},[27,425,54],{},[13,427,429],{"className":57,"code":428,"language":12,"meta":59,"style":59},"http {\n    sendfile      on;          # 零拷贝\n    tcp_nopush    on;          # 配合 sendfile，减少包数量\n    tcp_nodelay   on;          # 对 keepalive 连接，降低延迟\n}\n",[61,430,431,435,440,445,450],{"__ignoreMap":59},[64,432,433],{"class":66,"line":67},[64,434,277],{},[64,436,437],{"class":66,"line":73},[64,438,439],{},"    sendfile      on;          # 零拷贝\n",[64,441,442],{"class":66,"line":79},[64,443,444],{},"    tcp_nopush    on;          # 配合 sendfile，减少包数量\n",[64,446,447],{"class":66,"line":86},[64,448,449],{},"    tcp_nodelay   on;          # 对 keepalive 连接，降低延迟\n",[64,451,452],{"class":66,"line":92},[64,453,204],{},[23,455,456],{},[145,457,458],{},"三者在同一连接上可并存，内核会根据实际情况选择行为。",[32,460,462],{"id":461},"四启用-gzip-压缩","四、启用 Gzip 压缩",[23,464,465,467,469],{},[27,466,45],{},[47,468],{},"\n压缩响应体，节省带宽、加速传输，但消耗 CPU。需在压缩比率、压缩文件类型和 CPU 开销间取得平衡。",[23,471,472],{},[27,473,54],{},[13,475,477],{"className":57,"code":476,"language":12,"meta":59,"style":59},"http {\n    gzip on;\n    gzip_vary on;                     # 添加 Vary: Accept-Encoding 头\n    gzip_comp_level 5;               # 压缩级别 1-9，推荐 5-6\n    gzip_min_length 256;             # 过小文件不压缩\n    gzip_proxied any;                # 对代理请求也进行压缩判断\n    gzip_types\n        text\u002Fplain\n        text\u002Fcss\n        text\u002Fxml\n        text\u002Fjavascript\n        application\u002Fjavascript\n        application\u002Fxml+rss\n        application\u002Fjson\n        image\u002Fsvg+xml\n        application\u002Fx-font-ttf\n        font\u002Fopentype;\n    gzip_disable \"MSIE [1-6]\\.\";     # 对远古 IE 禁用\n}\n",[61,478,479,483,488,493,498,503,508,513,518,523,528,533,538,543,548,553,558,563,569],{"__ignoreMap":59},[64,480,481],{"class":66,"line":67},[64,482,277],{},[64,484,485],{"class":66,"line":73},[64,486,487],{},"    gzip on;\n",[64,489,490],{"class":66,"line":79},[64,491,492],{},"    gzip_vary on;                     # 添加 Vary: Accept-Encoding 头\n",[64,494,495],{"class":66,"line":86},[64,496,497],{},"    gzip_comp_level 5;               # 压缩级别 1-9，推荐 5-6\n",[64,499,500],{"class":66,"line":92},[64,501,502],{},"    gzip_min_length 256;             # 过小文件不压缩\n",[64,504,505],{"class":66,"line":299},[64,506,507],{},"    gzip_proxied any;                # 对代理请求也进行压缩判断\n",[64,509,510],{"class":66,"line":305},[64,511,512],{},"    gzip_types\n",[64,514,515],{"class":66,"line":311},[64,516,517],{},"        text\u002Fplain\n",[64,519,520],{"class":66,"line":317},[64,521,522],{},"        text\u002Fcss\n",[64,524,525],{"class":66,"line":323},[64,526,527],{},"        text\u002Fxml\n",[64,529,530],{"class":66,"line":329},[64,531,532],{},"        text\u002Fjavascript\n",[64,534,535],{"class":66,"line":335},[64,536,537],{},"        application\u002Fjavascript\n",[64,539,540],{"class":66,"line":341},[64,541,542],{},"        application\u002Fxml+rss\n",[64,544,545],{"class":66,"line":347},[64,546,547],{},"        application\u002Fjson\n",[64,549,550],{"class":66,"line":353},[64,551,552],{},"        image\u002Fsvg+xml\n",[64,554,555],{"class":66,"line":359},[64,556,557],{},"        application\u002Fx-font-ttf\n",[64,559,560],{"class":66,"line":364},[64,561,562],{},"        font\u002Fopentype;\n",[64,564,566],{"class":66,"line":565},18,[64,567,568],{},"    gzip_disable \"MSIE [1-6]\\.\";     # 对远古 IE 禁用\n",[64,570,572],{"class":66,"line":571},19,[64,573,204],{},[23,575,576,579,580,583,584,587,588,591],{},[27,577,578],{},"注意","：",[61,581,582],{},"gzip_comp_level"," 6 以上 CPU 开销急剧上升而压缩率收益递减，保持 5 左右即可。静态小文件可预先压缩为 ",[61,585,586],{},".gz"," 文件并结合 ",[61,589,590],{},"gzip_static"," 模块直接发送，极大节省 CPU。",[32,593,595],{"id":594},"五缓存配置","五、缓存配置",[37,597,599,600,603,604,110],{"id":598},"_1-浏览器缓存expires-cache-control","1. 浏览器缓存（",[61,601,602],{},"expires"," \u002F ",[61,605,606],{},"Cache-Control",[23,608,609,611,613],{},[27,610,45],{},[47,612],{},"\n通过设置响应头，让浏览器或中间代理缓存静态资源，消除重复请求，减少服务端压力和网络流量。",[23,615,616],{},[27,617,54],{},[13,619,621],{"className":57,"code":620,"language":12,"meta":59,"style":59},"location ~* \\.(jpg|jpeg|png|gif|ico|css|js|svg|woff2)$ {\n    expires 1y;                        # 一年后过期\n    add_header Cache-Control \"public, immutable\";\n    add_header Pragma public;\n    # 若文件名无版本号，可用短过期时间\n}\nlocation ~ \\.html$ {\n    expires -1;                        # 不缓存\n}\n",[61,622,623,628,633,638,643,648,652,657,662],{"__ignoreMap":59},[64,624,625],{"class":66,"line":67},[64,626,627],{},"location ~* \\.(jpg|jpeg|png|gif|ico|css|js|svg|woff2)$ {\n",[64,629,630],{"class":66,"line":73},[64,631,632],{},"    expires 1y;                        # 一年后过期\n",[64,634,635],{"class":66,"line":79},[64,636,637],{},"    add_header Cache-Control \"public, immutable\";\n",[64,639,640],{"class":66,"line":86},[64,641,642],{},"    add_header Pragma public;\n",[64,644,645],{"class":66,"line":92},[64,646,647],{},"    # 若文件名无版本号，可用短过期时间\n",[64,649,650],{"class":66,"line":299},[64,651,204],{},[64,653,654],{"class":66,"line":305},[64,655,656],{},"location ~ \\.html$ {\n",[64,658,659],{"class":66,"line":311},[64,660,661],{},"    expires -1;                        # 不缓存\n",[64,663,664],{"class":66,"line":317},[64,665,204],{},[23,667,668,579,671,673,674,677,678,681,682,685],{},[27,669,670],{},"细节",[61,672,602],{}," 指令会自动生成 ",[61,675,676],{},"Expires"," 和 ",[61,679,680],{},"Cache-Control: max-age","。对于带哈希的构建产物，设置长期缓存并配合不可变标记 ",[61,683,684],{},"immutable","。",[37,687,689,690,110],{"id":688},"_2-代理缓存proxy_cache","2. 代理缓存（",[61,691,692],{},"proxy_cache",[23,694,695,697,699],{},[27,696,45],{},[47,698],{},"\nNginx 将上游服务器的响应缓存到磁盘（或内存），后续相同请求直接从缓存返回，大幅度减轻后端负载和响应时间。适用于静态 API 响应、页面片段等。",[23,701,702],{},[27,703,704],{},"配置步骤",[13,706,708],{"className":57,"code":707,"language":12,"meta":59,"style":59},"http {\n    # 定义缓存路径和规则\n    proxy_cache_path \u002Fdata\u002Fnginx\u002Fcache levels=1:2 keys_zone=my_cache:10m\n                     max_size=10g inactive=60m use_temp_path=off;\n\n    server {\n        location \u002Fapi\u002F {\n            proxy_cache my_cache;\n            proxy_cache_key \"$scheme$request_method$host$request_uri\";\n            proxy_cache_valid 200 302 10m;\n            proxy_cache_valid 404      1m;\n            proxy_cache_use_stale error timeout updating;\n            # 支持条件请求，让客户端可验证缓存\n            proxy_cache_revalidate on;\n            proxy_pass http:\u002F\u002Fbackend;\n        }\n    }\n}\n",[61,709,710,714,719,724,729,733,737,742,747,752,757,762,767,772,777,781,785,789],{"__ignoreMap":59},[64,711,712],{"class":66,"line":67},[64,713,277],{},[64,715,716],{"class":66,"line":73},[64,717,718],{},"    # 定义缓存路径和规则\n",[64,720,721],{"class":66,"line":79},[64,722,723],{},"    proxy_cache_path \u002Fdata\u002Fnginx\u002Fcache levels=1:2 keys_zone=my_cache:10m\n",[64,725,726],{"class":66,"line":86},[64,727,728],{},"                     max_size=10g inactive=60m use_temp_path=off;\n",[64,730,731],{"class":66,"line":92},[64,732,83],{"emptyLinePlaceholder":82},[64,734,735],{"class":66,"line":299},[64,736,326],{},[64,738,739],{"class":66,"line":305},[64,740,741],{},"        location \u002Fapi\u002F {\n",[64,743,744],{"class":66,"line":311},[64,745,746],{},"            proxy_cache my_cache;\n",[64,748,749],{"class":66,"line":317},[64,750,751],{},"            proxy_cache_key \"$scheme$request_method$host$request_uri\";\n",[64,753,754],{"class":66,"line":323},[64,755,756],{},"            proxy_cache_valid 200 302 10m;\n",[64,758,759],{"class":66,"line":329},[64,760,761],{},"            proxy_cache_valid 404      1m;\n",[64,763,764],{"class":66,"line":335},[64,765,766],{},"            proxy_cache_use_stale error timeout updating;\n",[64,768,769],{"class":66,"line":341},[64,770,771],{},"            # 支持条件请求，让客户端可验证缓存\n",[64,773,774],{"class":66,"line":347},[64,775,776],{},"            proxy_cache_revalidate on;\n",[64,778,779],{"class":66,"line":353},[64,780,350],{},[64,782,783],{"class":66,"line":359},[64,784,356],{},[64,786,787],{"class":66,"line":364},[64,788,320],{},[64,790,791],{"class":66,"line":565},[64,792,204],{},[245,794,795,801,807,813],{},[248,796,797,800],{},[61,798,799],{},"keys_zone"," 设定共享内存区域名称和大小，存放缓存元数据。",[248,802,803,806],{},[61,804,805],{},"levels=1:2"," 配置两级子目录，避免单目录文件数过多。",[248,808,809,812],{},[61,810,811],{},"inactive"," 规定时间内访问则清除缓存。",[248,814,815,818],{},[61,816,817],{},"proxy_cache_use_stale"," 在后端异常时能交付过期缓存，保障可用性。",[37,820,822],{"id":821},"_3-快速缓存fastcgi-缓存等","3. 快速缓存（FastCGI 缓存等）",[23,824,825],{},"原理与代理缓存类似，针对 PHP 等 FastCGI 后端：",[13,827,829],{"className":57,"code":828,"language":12,"meta":59,"style":59},"fastcgi_cache_path \u002Fdata\u002Fnginx\u002Ffcgicache levels=1:2 keys_zone=fcgi:10m max_size=2g;\nfastcgi_cache fcgi;\nfastcgi_cache_key \"$scheme$request_method$host$request_uri\";\nfastcgi_cache_valid 200 10m;\n",[61,830,831,836,841,846],{"__ignoreMap":59},[64,832,833],{"class":66,"line":67},[64,834,835],{},"fastcgi_cache_path \u002Fdata\u002Fnginx\u002Ffcgicache levels=1:2 keys_zone=fcgi:10m max_size=2g;\n",[64,837,838],{"class":66,"line":73},[64,839,840],{},"fastcgi_cache fcgi;\n",[64,842,843],{"class":66,"line":79},[64,844,845],{},"fastcgi_cache_key \"$scheme$request_method$host$request_uri\";\n",[64,847,848],{"class":66,"line":86},[64,849,850],{},"fastcgi_cache_valid 200 10m;\n",[23,852,853,854,381,857,860],{},"同样适用于 ",[61,855,856],{},"uwsgi_cache",[61,858,859],{},"scgi_cache","，对动态内容可以显著加速。",[23,862,863],{},[27,864,865],{},"调优准则总结",[867,868,869,886,903],"ol",{},[248,870,871,874,875,878,879,381,882,885],{},[27,872,873],{},"先测量，后调优","——使用 ",[61,876,877],{},"nginx -V"," 检查编译参数，用访问日志记录 ",[61,880,881],{},"$request_time",[61,883,884],{},"$upstream_response_time"," 定位瓶颈。",[248,887,888,891,892],{},[27,889,890],{},"根据角色分层优化","：\n",[245,893,894,897,900],{},[248,895,896],{},"纯静态资源：重 sendfile + tcp_nopush + gzip_static + expires。",[248,898,899],{},"反向代理：keepalive 后端连接池 + proxy_cache + 合适的超时。",[248,901,902],{},"全栈站点：动静分离，动态部分走缓存或加速。",[248,904,905,908,909,381,912,381,915,918],{},[27,906,907],{},"压力测试验证","：每项调优后使用 ",[61,910,911],{},"wrk",[61,913,914],{},"ab",[61,916,917],{},"vegeta"," 等工具压测，对比 QPS、响应时间分布和错误率。",[23,920,921],{},"把这些优化项逐一落实并测试，你的 Nginx 就能真正地“快、稳、省”。",[923,924,925],"h2",{"id":925},"参考文献",[927,928,929,942],"table",{},[930,931,932],"thead",{},[933,934,935,939],"tr",{},[936,937,938],"th",{},"资料",[936,940,941],{},"说明",[943,944,945,960],"tbody",{},[933,946,947,957],{},[948,949,950],"td",{},[951,952,956],"a",{"href":953,"rel":954},"https:\u002F\u002Fnginx.org\u002Fen\u002Fdocs\u002F",[955],"nofollow","nginx 文档",[948,958,959],{},"官方",[933,961,962,968],{},[948,963,964],{},[951,965,967],{"href":966},"\u002Fknowledge\u002Fbooklet\u002Fuphold","运维导读",[948,969,970],{},"学习路径",[972,973,974],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":59,"searchDepth":73,"depth":73,"links":976},[977,978,979,980,981,982],{"id":34,"depth":79,"text":35},{"id":150,"depth":79,"text":151},{"id":372,"depth":79,"text":373},{"id":461,"depth":79,"text":462},{"id":594,"depth":79,"text":595},{"id":925,"depth":73,"text":925},{"title":8,"description":9},"knowledge\u002Fbooklet\u002Fuphold\u002FNginx\u002Fpre","knowledge\u002Fknowledge\u002Fbooklet\u002Fuphold\u002FNginx\u002Fpre.md","md",{"items":988},[989,993,997,1001,1005,1009],{"path":990,"title":991,"description":992,"category":10,"score":299},"\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Fse","安全基础","Nginx 作为流量的总入口，安全配置是防线第一关。以下从六个基础维度加固你的服务，既实用又立竿见影。",{"path":994,"title":995,"description":996,"category":10,"score":299},"\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Fconfig","配置文件结构与语法","下面我们深入到 Nginx 的配置核心——配置文件的结构、语法和变量系统。这一部分是你驾驭 Nginx 的“语法手册”。",{"path":998,"title":999,"description":1000,"category":10,"score":299},"\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Fcore","核心模块与常见指令详解","深入 Nginx 的指令层，是配置落地的关键。下面按功能模块拆解，每个指令都说明含义、语法、典型示例，并点出极易踩坑的地方。",{"path":1002,"title":1003,"description":1004,"category":10,"score":299},"\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Fbase","Nginx 核心概念","Nginx 是一款高性能的 HTTP 和反向代理服务器。学习路径见 运维导读。它的强大并发能力与灵活的扩展性根植于少数几个核心设计。理解这些底层原理，后续的配置、调优和排障都会变得通透。",{"path":1006,"title":1007,"description":1008,"category":10,"score":299},"\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Fseror","常见故障排查思路","故障排查的关键是快速定位，而非盲目重试。下面按最常见的五种现象归类，每一种都给出清晰的排查路径和解决思路。",{"path":1010,"title":1011,"description":1012,"category":10,"score":299},"\u002Fknowledge\u002Fbooklet\u002Fuphold\u002Fnginx\u002Flogger","访问日志与错误日志","日志是 Nginx 排错的“第一现场”。一个优秀的日志策略既能完整保留请求上下文，又不会撑爆磁盘。下面从格式定制、存储轮转、错误分级三个维度详细讲解。",{"series":1014,"title":12,"items":1015,"index":86,"prev":1029,"next":1030},"booklet\u002Fuphold\u002Fnginx",[1016,1018,1020,1022,1024,1025,1027],{"path":1002,"title":1003,"date":1017,"pinned":15},"2023-04-03",{"path":994,"title":995,"date":1019,"pinned":15},"2023-11-24",{"path":998,"title":999,"date":1021,"pinned":15},"2023-04-25",{"path":1010,"title":1011,"date":1023,"pinned":15},"2020-02-29",{"path":7,"title":8,"date":14,"pinned":15},{"path":990,"title":991,"date":1026,"pinned":15},"2024-12-02",{"path":1006,"title":1007,"date":1028,"pinned":15},"2020-09-18",{"path":1010,"title":1011,"date":1023,"pinned":15},{"path":990,"title":991,"date":1026,"pinned":15}]