{"id":113433,"date":"2026-10-06T10:49:38","date_gmt":"2026-10-06T02:49:38","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/113433.html"},"modified":"2026-10-06T10:49:38","modified_gmt":"2026-10-06T02:49:38","slug":"nginx-%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e6%8c%87%e5%8d%97%ef%bc%9a%e5%bc%80%e5%90%af-gzip%e3%80%81keepalive-%e4%b8%8e-%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1%e9%85%8d%e7%bd%ae%ef%bc%8c%e8%ae%a9","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/113433.html","title":{"rendered":"Nginx \u6027\u80fd\u8c03\u4f18\u6307\u5357\uff1a\u5f00\u542f Gzip\u3001KeepAlive \u4e0e \u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\uff0c\u8ba9\u4f60\u7684\u670d\u52a1\u5668\u541e\u5410\u91cf\u7ffb\u500d"},"content":{"rendered":"<h4>&#x1f422; \u524d\u8a00&#xff1a;\u4f60\u7684 Nginx \u771f\u7684\u201c\u706b\u529b\u5168\u5f00\u201d\u4e86\u5417&#xff1f;<\/h4>\n<p>Nginx \u4ee5\u9ad8\u6027\u80fd\u8457\u79f0&#xff0c;\u4f46\u5728\u9ed8\u8ba4\u5b89\u88c5\u4e0b&#xff0c;\u5b83\u5c31\u50cf\u4e00\u8f86\u88ab\u9650\u901f\u7684\u6cd5\u62c9\u5229&#xff1a;<\/p>\n<li>\u5e26\u5bbd\u6d6a\u8d39&#xff1a;\u51e0\u5341 KB \u7684 JSON \u6570\u636e\u539f\u6837\u4f20\u8f93&#xff0c;\u6ca1\u6709\u538b\u7f29\u3002<\/li>\n<li>\u8fde\u63a5\u6d88\u8017&#xff1a;\u6bcf\u6b21\u8bf7\u6c42\u90fd\u91cd\u65b0\u5efa\u7acb TCP \u63e1\u624b&#xff0c;CPU \u90fd\u5728\u5904\u7406\u63e1\u624b\u6325\u624b&#xff0c;\u6ca1\u7a7a\u5904\u7406\u4e1a\u52a1\u3002<\/li>\n<li>\u5355\u70b9\u74f6\u9888&#xff1a;\u6d41\u91cf\u5168\u538b\u5728\u4e00\u53f0\u540e\u7aef\u4e0a&#xff0c;\u6ca1\u6709\u5206\u6d41\u3002<\/li>\n<p>\u522b\u62c5\u5fc3&#xff0c;\u53ea\u9700\u52a8\u52a8 nginx.conf&#xff0c;\u6211\u4eec\u5c31\u80fd\u89e3\u9501\u5b83\u7684\u5168\u90e8\u6f5c\u80fd\u3002<\/p>\n<hr \/>\n<h4>&#x1f4e6; \u4e00\u3001 \u5f00\u542f Gzip&#xff1a;\u7ed9\u6d41\u91cf\u201c\u7626\u8eab\u201d<\/h4>\n<p>\u539f\u7406&#xff1a;<br \/>\nGzip \u5c31\u50cf\u6253\u5305\u884c\u674e\u65f6\u7684\u771f\u7a7a\u888b\u3002\u5b83\u80fd\u5c06 HTML\u3001CSS\u3001JS \u548c JSON \u6587\u672c\u7684\u5927\u5c0f\u538b\u7f29 70% \u4ee5\u4e0a\u3002\u8fd9\u610f\u5473\u7740\u540c\u6837\u7684\u5e26\u5bbd&#xff0c;\u4f60\u80fd\u627f\u8f7d\u66f4\u591a\u7684\u5e76\u53d1\u8bf7\u6c42&#xff0c;\u4e14\u7528\u6237\u52a0\u8f7d\u901f\u5ea6\u66f4\u5feb\u3002<\/p>\n<p>\u5b9e\u6218\u914d\u7f6e&#xff1a;<\/p>\n<p>http {<br \/>\n    # \u5f00\u542f Gzip<br \/>\n    gzip on;<\/p>\n<p>    # \u542f\u7528 Gzip \u7684\u6700\u5c0f\u6587\u4ef6\u5927\u5c0f&#xff0c;\u592a\u5c0f\u7684\u6587\u4ef6\u538b\u7f29\u53cd\u800c\u4e8f\u672c&#xff08;CPU\u6d88\u8017&#xff09;<br \/>\n    gzip_min_length 1k;<\/p>\n<p>    # \u538b\u7f29\u7ea7\u522b (1-9)&#xff0c;\u5efa\u8bae 4-6\u3002\u7ea7\u522b\u8d8a\u9ad8\u538b\u7f29\u7387\u8d8a\u9ad8&#xff0c;\u4f46\u4e5f\u8d8a\u5403 CPU<br \/>\n    gzip_comp_level 6;<\/p>\n<p>    # \u9700\u8981\u538b\u7f29\u7684\u6587\u4ef6\u7c7b\u578b (\u5343\u4e07\u522b\u6f0f\u4e86 application\/json)<br \/>\n    gzip_types text\/plain text\/css application\/json application\/javascript text\/xml application\/xml application\/xml&#043;rss text\/javascript;<\/p>\n<p>    # \u662f\u5426\u4f20\u8f93 &#034;Vary: Accept-Encoding&#034; \u5934&#xff0c;\u544a\u8bc9\u4ee3\u7406\u670d\u52a1\u5668\u7f13\u5b58\u4e24\u79cd\u7248\u672c<br \/>\n    gzip_vary on;<\/p>\n<p>    # \u7981\u7528 IE6 \u7684 gzip (\u867d\u7136\u73b0\u5728\u4e5f\u6ca1\u4eba\u7528\u4e86)<br \/>\n    gzip_disable &#034;MSIE [1-6]\\\\.&#034;;<br \/>\n}<\/p>\n<p>\u6548\u679c\u7acb\u7aff\u89c1\u5f71&#xff1a;\u4e00\u4e2a 100KB \u7684 API \u54cd\u5e94&#xff0c;\u538b\u7f29\u540e\u53ef\u80fd\u53ea\u6709 20KB\u3002\u5e26\u5bbd\u5360\u7528\u76f4\u63a5\u4e0b\u964d 5 \u500d&#xff01;<\/p>\n<hr \/>\n<h4>&#x1f91d; \u4e8c\u3001 \u4f18\u5316 KeepAlive&#xff1a;\u62d2\u7edd\u9891\u7e41\u201c\u63e1\u624b\u201d<\/h4>\n<p>\u539f\u7406&#xff1a;<br \/>\nHTTP \u662f\u57fa\u4e8e TCP \u7684\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff08;HTTP\/1.0&#xff09;&#xff0c;\u6bcf\u6b21\u8bf7\u6c42\u90fd\u8981\u7ecf\u5386 SYN -&gt; SYN-ACK -&gt; ACK \u4e09\u6b21\u63e1\u624b&#xff0c;\u4f20\u5b8c\u6570\u636e\u53c8\u8981\u56db\u6b21\u6325\u624b\u3002<br \/>\nKeepAlive \u5141\u8bb8\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u590d\u7528\u540c\u4e00\u4e2a TCP \u8fde\u63a5\u53d1\u9001\u591a\u4e2a\u8bf7\u6c42\u3002\u8fd9\u80fd\u6781\u5927\u964d\u4f4e CPU \u5f00\u9500\u548c\u7f51\u7edc\u5ef6\u8fdf\u3002<\/p>\n<p>\u5b9e\u6218\u914d\u7f6e (\u4e24\u5904\u90fd\u8981\u6539)&#xff1a;<\/p>\n<p>1. \u5ba2\u6237\u7aef\u5230 Nginx \u7684\u8fde\u63a5<\/p>\n<p>http {<br \/>\n    # \u5ba2\u6237\u7aef\u8fde\u63a5\u4fdd\u6301\u65f6\u95f4&#xff0c;\u5efa\u8bae 65s<br \/>\n    keepalive_timeout 65;<\/p>\n<p>    # \u4e00\u4e2a KeepAlive \u8fde\u63a5\u6700\u591a\u5904\u7406\u591a\u5c11\u4e2a\u8bf7\u6c42\u540e\u5f3a\u5236\u5173\u95ed<br \/>\n    keepalive_requests 10000;<br \/>\n}<\/p>\n<p>2. Nginx \u5230\u540e\u7aef\u5e94\u7528 (Upstream) \u7684\u8fde\u63a5 \u2014\u2014 \u91cd\u70b9&#xff01;<br \/>\n\u8fd9\u662f\u5f88\u591a\u4eba\u7684\u76f2\u533a\u3002Nginx \u9ed8\u8ba4\u5bf9\u540e\u7aef\u662f\u77ed\u8fde\u63a5\u3002\u8981\u5f00\u542f\u957f\u8fde\u63a5&#xff0c;\u5fc5\u987b\u914d\u7f6e upstream \u5757\u3002<\/p>\n<p>upstream backend_server {<br \/>\n    server 127.0.0.1:8080;<\/p>\n<p>    # \u6838\u5fc3&#xff1a;\u4fdd\u6301\u4e0e\u540e\u7aef\u7684\u7a7a\u95f2\u957f\u8fde\u63a5\u6570\u91cf<br \/>\n    keepalive 32;<br \/>\n}<\/p>\n<p>server {<br \/>\n    location \/api\/ {<br \/>\n        proxy_pass http:\/\/backend_server;<\/p>\n<p>        # \u6838\u5fc3&#xff1a;\u5fc5\u987b\u8bbe\u7f6e HTTP \u7248\u672c\u4e3a 1.1<br \/>\n        proxy_http_version 1.1;<\/p>\n<p>        # \u6838\u5fc3&#xff1a;\u6e05\u9664 Connection \u5934&#xff0c;\u9632\u6b62\u4f20\u9012 &#034;close&#034; \u7ed9\u540e\u7aef<br \/>\n        proxy_set_header Connection &#034;&#034;;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u907f\u5751&#xff1a;\u5982\u679c\u4e0d\u914d\u7f6e proxy_set_header Connection &#034;&#034;;&#xff0c;Nginx \u8f6c\u53d1\u65f6\u4f1a\u81ea\u52a8\u52a0\u4e0a Connection: close&#xff0c;\u5bfc\u81f4\u540e\u7aef&#xff08;\u5982 Tomcat\/Go&#xff09;\u4e0d\u4ec5\u6ca1\u4eab\u53d7\u5230\u957f\u8fde\u63a5&#xff0c;\u8fd8\u5f97\u5904\u7406\u9891\u7e41\u65ad\u5f00\u7684\u5f00\u9500\u3002<\/p>\n<hr \/>\n<h4>\u2696\ufe0f \u4e09\u3001 \u8d1f\u8f7d\u5747\u8861&#xff1a;\u6d41\u91cf\u5206\u53d1\u827a\u672f<\/h4>\n<p>\u539f\u7406&#xff1a;<br \/>\n\u5f53\u5355\u673a\u6491\u4e0d\u4f4f\u65f6&#xff0c;\u6211\u4eec\u9700\u8981\u628a\u6d41\u91cf\u5206\u53d1\u7ed9\u591a\u53f0\u670d\u52a1\u5668\u3002Nginx \u539f\u751f\u652f\u6301\u591a\u79cd\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u3002<\/p>\n<p>\u67b6\u6784\u56fe (Mermaid):<\/p>\n<p>#mermaid-svg-SWspk4R5lIDlEht5{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-SWspk4R5lIDlEht5 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-SWspk4R5lIDlEht5 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-SWspk4R5lIDlEht5 .error-icon{fill:#552222;}#mermaid-svg-SWspk4R5lIDlEht5 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-SWspk4R5lIDlEht5 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-SWspk4R5lIDlEht5 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-SWspk4R5lIDlEht5 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-SWspk4R5lIDlEht5 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-SWspk4R5lIDlEht5 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-SWspk4R5lIDlEht5 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-SWspk4R5lIDlEht5 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-SWspk4R5lIDlEht5 .marker.cross{stroke:#333333;}#mermaid-svg-SWspk4R5lIDlEht5 svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-SWspk4R5lIDlEht5 p{margin:0;}#mermaid-svg-SWspk4R5lIDlEht5 .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-SWspk4R5lIDlEht5 .cluster-label text{fill:#333;}#mermaid-svg-SWspk4R5lIDlEht5 .cluster-label span{color:#333;}#mermaid-svg-SWspk4R5lIDlEht5 .cluster-label span p{background-color:transparent;}#mermaid-svg-SWspk4R5lIDlEht5 .label text,#mermaid-svg-SWspk4R5lIDlEht5 span{fill:#333;color:#333;}#mermaid-svg-SWspk4R5lIDlEht5 .node rect,#mermaid-svg-SWspk4R5lIDlEht5 .node circle,#mermaid-svg-SWspk4R5lIDlEht5 .node ellipse,#mermaid-svg-SWspk4R5lIDlEht5 .node polygon,#mermaid-svg-SWspk4R5lIDlEht5 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-SWspk4R5lIDlEht5 .rough-node .label text,#mermaid-svg-SWspk4R5lIDlEht5 .node .label text,#mermaid-svg-SWspk4R5lIDlEht5 .image-shape .label,#mermaid-svg-SWspk4R5lIDlEht5 .icon-shape .label{text-anchor:middle;}#mermaid-svg-SWspk4R5lIDlEht5 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-SWspk4R5lIDlEht5 .rough-node .label,#mermaid-svg-SWspk4R5lIDlEht5 .node .label,#mermaid-svg-SWspk4R5lIDlEht5 .image-shape .label,#mermaid-svg-SWspk4R5lIDlEht5 .icon-shape .label{text-align:center;}#mermaid-svg-SWspk4R5lIDlEht5 .node.clickable{cursor:pointer;}#mermaid-svg-SWspk4R5lIDlEht5 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-SWspk4R5lIDlEht5 .arrowheadPath{fill:#333333;}#mermaid-svg-SWspk4R5lIDlEht5 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-SWspk4R5lIDlEht5 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-SWspk4R5lIDlEht5 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-SWspk4R5lIDlEht5 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-SWspk4R5lIDlEht5 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-SWspk4R5lIDlEht5 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-SWspk4R5lIDlEht5 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-SWspk4R5lIDlEht5 .cluster text{fill:#333;}#mermaid-svg-SWspk4R5lIDlEht5 .cluster span{color:#333;}#mermaid-svg-SWspk4R5lIDlEht5 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-SWspk4R5lIDlEht5 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-SWspk4R5lIDlEht5 rect.text{fill:none;stroke-width:0;}#mermaid-svg-SWspk4R5lIDlEht5 .icon-shape,#mermaid-svg-SWspk4R5lIDlEht5 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-SWspk4R5lIDlEht5 .icon-shape p,#mermaid-svg-SWspk4R5lIDlEht5 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-SWspk4R5lIDlEht5 .icon-shape rect,#mermaid-svg-SWspk4R5lIDlEht5 .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-SWspk4R5lIDlEht5 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-SWspk4R5lIDlEht5 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-SWspk4R5lIDlEht5 :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<span class=\"nodeLabel\"><\/p>\n<p>\u540e\u7aef\u96c6\u7fa4<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>HTTP\/HTTPS<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u8f6e\u8be2\/\u6743\u91cd<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u6743\u91cd\/Hash<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u5907\u4efd<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u6d77\u91cf\u7528\u6237\u8bf7\u6c42<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>Nginx (\u8d1f\u8f7d\u5747\u8861\u5668)<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>App Server 1 (8080)<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>App Server 2 (8081)<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>App Server 3 (8082)<\/p>\n<p><\/span><\/p>\n<p>\u5b9e\u6218\u914d\u7f6e&#xff1a;<\/p>\n<p>upstream my_app {<br \/>\n    # \u7b56\u7565 1&#xff1a;\u8f6e\u8be2 (\u9ed8\u8ba4) &#8211; \u5e73\u5747\u5206\u914d<br \/>\n    # server 192.168.1.101;<br \/>\n    # server 192.168.1.102;<\/p>\n<p>    # \u7b56\u7565 2&#xff1a;\u52a0\u6743\u8f6e\u8be2 &#8211; \u6027\u80fd\u597d\u7684\u673a\u5668\u591a\u5206\u70b9<br \/>\n    server 192.168.1.101 weight&#061;3;<br \/>\n    server 192.168.1.102 weight&#061;1;<\/p>\n<p>    # \u7b56\u7565 3&#xff1a;ip_hash &#8211; \u4fdd\u8bc1\u540c\u4e00\u4e2a\u7528\u6237 IP \u603b\u662f\u8bbf\u95ee\u540c\u4e00\u53f0\u673a\u5668 (\u89e3\u51b3 Session \u95ee\u9898)<br \/>\n    # ip_hash;<br \/>\n    # server 192.168.1.101;<br \/>\n    # server 192.168.1.102;<\/p>\n<p>    # \u7b56\u7565 4&#xff1a;least_conn &#8211; \u8c01\u8fde\u63a5\u6570\u5c11\u53d1\u7ed9\u8c01 (\u6700\u667a\u80fd)<br \/>\n    least_conn;<br \/>\n    server 192.168.1.101;<br \/>\n    server 192.168.1.102;<\/p>\n<p>    # \u5bb9\u707e\u914d\u7f6e<br \/>\n    server 192.168.1.103 backup; # \u5176\u4ed6\u673a\u5668\u90fd\u6302\u4e86\u624d\u7528\u5b83<br \/>\n}<\/p>\n<hr \/>\n<h4>&#x1f680; \u56db\u3001 \u8865\u5145&#xff1a;Worker \u8fdb\u7a0b\u4f18\u5316<\/h4>\n<p>\u9664\u4e86\u4e0a\u8ff0\u4e09\u70b9&#xff0c;\u8fd8\u6709\u4e00\u4e2a\u57fa\u7840\u914d\u7f6e\u51b3\u5b9a\u4e86\u5e76\u53d1\u4e0a\u9650\u3002<\/p>\n<p># \u81ea\u52a8\u6839\u636e CPU \u6838\u6570\u8bbe\u7f6e Worker \u8fdb\u7a0b\u6570<br \/>\nworker_processes auto;<\/p>\n<p>events {<br \/>\n    # \u6bcf\u4e2a Worker \u5141\u8bb8\u7684\u6700\u5927\u8fde\u63a5\u6570<br \/>\n    # \u603b\u5e76\u53d1\u4e0a\u9650 \u2248 worker_processes * worker_connections<br \/>\n    # \u5fc5\u987b\u914d\u5408 Linux \u7684 ulimit -n \u4f7f\u7528 (\u6587\u4ef6\u63cf\u8ff0\u7b26\u9650\u5236)<br \/>\n    worker_connections 10240;<\/p>\n<p>    # \u5f00\u542f epoll \u6a21\u578b (Linux \u9ad8\u6027\u80fd\u6838\u5fc3)<br \/>\n    use epoll;<\/p>\n<p>    # \u5141\u8bb8\u4e00\u4e2a Worker \u540c\u65f6\u63a5\u53d7\u591a\u4e2a\u65b0\u8fde\u63a5<br \/>\n    multi_accept on;<br \/>\n}<\/p>\n<hr \/>\n<h4>&#x1f4ca; \u4e94\u3001 \u6548\u679c\u9a8c\u8bc1<\/h4>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 wrk \u6216 ab \u538b\u6d4b\u5de5\u5177\u6765\u5bf9\u6bd4\u4f18\u5316\u524d\u540e\u7684\u6548\u679c\u3002<\/p>\n<p>\u547d\u4ee4\u793a\u4f8b&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u6a21\u62df 100 \u4e2a\u8fde\u63a5&#xff0c;\u6301\u7eed 30 \u79d2<\/span><br \/>\nwrk <span class=\"token parameter variable\">-t12<\/span> <span class=\"token parameter variable\">-c100<\/span> <span class=\"token parameter variable\">-d30s<\/span> http:\/\/localhost\/api\/test<\/p>\n<p>\u9884\u671f\u7ed3\u679c&#xff1a;<\/p>\n<ul>\n<li>Requests\/sec (QPS)&#xff1a;\u5728\u5f00\u542f KeepAlive \u548c Gzip \u540e&#xff0c;\u901a\u5e38\u4f1a\u6709 50% &#8211; 200% \u7684\u63d0\u5347\u3002<\/li>\n<li>Transfer\/sec&#xff1a;\u7531\u4e8e Gzip&#xff0c;\u4f20\u8f93\u6d41\u91cf\u4f1a\u663e\u8457\u4e0b\u964d\u3002<\/li>\n<li>Socket Errors&#xff1a;\u5728\u9ad8\u5e76\u53d1\u4e0b&#xff0c;\u8fde\u63a5\u9519\u8bef\u6570\u4f1a\u5927\u5e45\u51cf\u5c11&#xff08;\u56e0\u4e3a\u8fde\u63a5\u590d\u7528\u4e86&#xff09;\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>&#x1f3af; \u603b\u7ed3<\/h4>\n<p>Nginx \u8c03\u4f18\u5e76\u4e0d\u7384\u5b66&#xff0c;\u6838\u5fc3\u5c31\u5728\u4e8e&#xff1a;<\/p>\n<li>Gzip&#xff1a;\u7528 CPU \u6362\u5e26\u5bbd\u3002<\/li>\n<li>KeepAlive&#xff1a;\u7528\u5185\u5b58\u6362 CPU \u548c \u5ef6\u8fdf\u3002<\/li>\n<li>Load Balance&#xff1a;\u6a2a\u5411\u6269\u5c55&#xff0c;\u5206\u62c5\u538b\u529b\u3002<\/li>\n<p>\u8fd9\u4e09\u677f\u65a7\u4e0b\u53bb&#xff0c;\u4f60\u7684\u670d\u52a1\u5668\u5c31\u50cf\u5378\u4e0b\u4e86\u6c99\u888b&#xff0c;\u8dd1\u5f97\u98de\u8d77&#xff01;<\/p>\n<p>Next Step:<br \/>\n\u767b\u5f55\u4f60\u7684\u670d\u52a1\u5668&#xff0c;\u68c0\u67e5\u4e00\u4e0b nginx.conf\u3002\u5982\u679c\u770b\u5230 gzip \u662f\u6ce8\u91ca\u72b6\u6001&#xff0c;\u6216\u8005 upstream \u91cc\u6ca1\u6709 keepalive&#xff0c;\u54ea\u6015\u73b0\u5728\u6d41\u91cf\u4e0d\u5927&#xff0c;\u4e5f\u8bf7\u8d76\u7d27\u6539\u8fc7\u6765\u3002\u8fd9\u662f\u4e13\u4e1a\u7d20\u517b\u7684\u4f53\u73b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f422; \u524d\u8a00&#xff1a;\u4f60\u7684 Nginx \u771f\u7684\u201c\u706b\u529b\u5168\u5f00\u201d\u4e86\u5417&#xff1f;<br \/>\nNginx \u4ee5\u9ad8\u6027\u80fd\u8457\u79f0&#xff0c;\u4f46\u5728\u9ed8\u8ba4\u5b89\u88c5\u4e0b&#xff0c;\u5b83\u5c31\u50cf\u4e00\u8f86\u88ab\u9650\u901f\u7684\u6cd5\u62c9\u5229&#xff1a;<br \/>\n\u5e26\u5bbd\u6d6a\u8d39&#xff1a;\u51e0\u5341 KB \u7684 JSON \u6570\u636e\u539f\u6837\u4f20\u8f93&#xff0c;\u6ca1\u6709\u538b\u7f29\u3002\u8fde\u63a5\u6d88\u8017&#xff1a;\u6bcf\u6b21\u8bf7\u6c42\u90fd\u91cd\u65b0\u5efa\u7acb TCP \u63e1\u624b&#xff0c;CPU \u90fd\u5728\u5904\u7406\u63e1\u624b\u6325\u624b&#xff0c;\u6ca1\u7a7a\u5904\u7406\u4e1a\u52a1\u3002\u5355\u70b9\u74f6\u9888&#xff1a;\u6d41\u91cf\u5168\u538b\u5728\u4e00\u53f0\u540e\u7aef\u4e0a&amp;#xff0c<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[117,43,258],"topic":[],"class_list":["post-113433","post","type-post","status-publish","format-standard","hentry","category-server","tag-nginx","tag-43","tag-258"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Nginx \u6027\u80fd\u8c03\u4f18\u6307\u5357\uff1a\u5f00\u542f Gzip\u3001KeepAlive \u4e0e \u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\uff0c\u8ba9\u4f60\u7684\u670d\u52a1\u5668\u541e\u5410\u91cf\u7ffb\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/113433.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Nginx \u6027\u80fd\u8c03\u4f18\u6307\u5357\uff1a\u5f00\u542f Gzip\u3001KeepAlive \u4e0e \u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\uff0c\u8ba9\u4f60\u7684\u670d\u52a1\u5668\u541e\u5410\u91cf\u7ffb\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"&#x1f422; \u524d\u8a00&#xff1a;\u4f60\u7684 Nginx \u771f\u7684\u201c\u706b\u529b\u5168\u5f00\u201d\u4e86\u5417&#xff1f; Nginx \u4ee5\u9ad8\u6027\u80fd\u8457\u79f0&#xff0c;\u4f46\u5728\u9ed8\u8ba4\u5b89\u88c5\u4e0b&#xff0c;\u5b83\u5c31\u50cf\u4e00\u8f86\u88ab\u9650\u901f\u7684\u6cd5\u62c9\u5229&#xff1a; \u5e26\u5bbd\u6d6a\u8d39&#xff1a;\u51e0\u5341 KB \u7684 JSON \u6570\u636e\u539f\u6837\u4f20\u8f93&#xff0c;\u6ca1\u6709\u538b\u7f29\u3002\u8fde\u63a5\u6d88\u8017&#xff1a;\u6bcf\u6b21\u8bf7\u6c42\u90fd\u91cd\u65b0\u5efa\u7acb TCP \u63e1\u624b&#xff0c;CPU \u90fd\u5728\u5904\u7406\u63e1\u624b\u6325\u624b&#xff0c;\u6ca1\u7a7a\u5904\u7406\u4e1a\u52a1\u3002\u5355\u70b9\u74f6\u9888&#xff1a;\u6d41\u91cf\u5168\u538b\u5728\u4e00\u53f0\u540e\u7aef\u4e0a&amp;#xff0c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/113433.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-06T02:49:38+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113433.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/113433.html\",\"name\":\"Nginx \u6027\u80fd\u8c03\u4f18\u6307\u5357\uff1a\u5f00\u542f Gzip\u3001KeepAlive \u4e0e \u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\uff0c\u8ba9\u4f60\u7684\u670d\u52a1\u5668\u541e\u5410\u91cf\u7ffb\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-06T02:49:38+00:00\",\"dateModified\":\"2026-10-06T02:49:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/113433.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/113433.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113433.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Nginx \u6027\u80fd\u8c03\u4f18\u6307\u5357\uff1a\u5f00\u542f Gzip\u3001KeepAlive \u4e0e \u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\uff0c\u8ba9\u4f60\u7684\u670d\u52a1\u5668\u541e\u5410\u91cf\u7ffb\u500d\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Nginx \u6027\u80fd\u8c03\u4f18\u6307\u5357\uff1a\u5f00\u542f Gzip\u3001KeepAlive \u4e0e \u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\uff0c\u8ba9\u4f60\u7684\u670d\u52a1\u5668\u541e\u5410\u91cf\u7ffb\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/113433.html","og_locale":"zh_CN","og_type":"article","og_title":"Nginx \u6027\u80fd\u8c03\u4f18\u6307\u5357\uff1a\u5f00\u542f Gzip\u3001KeepAlive \u4e0e \u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\uff0c\u8ba9\u4f60\u7684\u670d\u52a1\u5668\u541e\u5410\u91cf\u7ffb\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"&#x1f422; \u524d\u8a00&#xff1a;\u4f60\u7684 Nginx \u771f\u7684\u201c\u706b\u529b\u5168\u5f00\u201d\u4e86\u5417&#xff1f; Nginx \u4ee5\u9ad8\u6027\u80fd\u8457\u79f0&#xff0c;\u4f46\u5728\u9ed8\u8ba4\u5b89\u88c5\u4e0b&#xff0c;\u5b83\u5c31\u50cf\u4e00\u8f86\u88ab\u9650\u901f\u7684\u6cd5\u62c9\u5229&#xff1a; \u5e26\u5bbd\u6d6a\u8d39&#xff1a;\u51e0\u5341 KB \u7684 JSON \u6570\u636e\u539f\u6837\u4f20\u8f93&#xff0c;\u6ca1\u6709\u538b\u7f29\u3002\u8fde\u63a5\u6d88\u8017&#xff1a;\u6bcf\u6b21\u8bf7\u6c42\u90fd\u91cd\u65b0\u5efa\u7acb TCP \u63e1\u624b&#xff0c;CPU \u90fd\u5728\u5904\u7406\u63e1\u624b\u6325\u624b&#xff0c;\u6ca1\u7a7a\u5904\u7406\u4e1a\u52a1\u3002\u5355\u70b9\u74f6\u9888&#xff1a;\u6d41\u91cf\u5168\u538b\u5728\u4e00\u53f0\u540e\u7aef\u4e0a&amp;#xff0c","og_url":"https:\/\/www.wsisp.com\/helps\/113433.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-06T02:49:38+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/113433.html","url":"https:\/\/www.wsisp.com\/helps\/113433.html","name":"Nginx \u6027\u80fd\u8c03\u4f18\u6307\u5357\uff1a\u5f00\u542f Gzip\u3001KeepAlive \u4e0e \u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\uff0c\u8ba9\u4f60\u7684\u670d\u52a1\u5668\u541e\u5410\u91cf\u7ffb\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-06T02:49:38+00:00","dateModified":"2026-10-06T02:49:38+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/113433.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/113433.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/113433.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Nginx \u6027\u80fd\u8c03\u4f18\u6307\u5357\uff1a\u5f00\u542f Gzip\u3001KeepAlive \u4e0e \u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\uff0c\u8ba9\u4f60\u7684\u670d\u52a1\u5668\u541e\u5410\u91cf\u7ffb\u500d"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/113433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=113433"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/113433\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=113433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=113433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=113433"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=113433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}