{"id":513,"date":"2026-01-27T02:42:48","date_gmt":"2026-01-27T02:42:48","guid":{"rendered":"https:\/\/blog.gpst.net.cn:4008\/?p=513"},"modified":"2026-01-28T06:24:12","modified_gmt":"2026-01-28T06:24:12","slug":"nginx-brotli%e5%8e%8b%e7%bc%a9%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/opshub.com.cn\/?p=513","title":{"rendered":"Nginx Brotli\u538b\u7f29\u7b97\u6cd5"},"content":{"rendered":"\n<p>Brotli \u662f\u57fa\u4e8eLZ77\u7b97\u6cd5\u7684\u4e00\u4e2a\u73b0\u4ee3\u53d8\u4f53\u3001\u970d\u592b\u66fc\u7f16\u7801\u3002 Google\u8f6f\u4ef6\u5de5\u7a0b\u5e08 \u57282015\u5e749\u6708\u53d1\u5e03\u4e86\u5305\u542b\u901a\u7528\u65e0\u635f\u6570\u636e\u538b\u7f29\u7684Brotli\u589e\u5f3a\u7248\u672c\uff0c\u7279\u522b\u4fa7\u91cd\u4e8eHTTP\u538b\u7f29\u3002 \u6ce8\u610f\uff1a\u4f7f\u7528\u7b97\u6cd5\u7684\u524d\u63d0\u662f\u542f\u7528\u4e86 https\uff0c\u56e0\u4e3a\u00a0http \u8bf7\u6c42\u4e2d\u00a0<strong>request header<\/strong>\u00a0\u91cc\u7684\u00a0<strong>Accept-Encoding: gzip, deflate<\/strong>\u00a0\u662f\u6ca1\u6709 br \u7684\u3002<\/p>\n\n\n\n<p>1\u3001\u83b7\u53d6brotli\u6a21\u5757<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/root\nexport https_proxy=http:\/\/relay-actting.iftop.top:11969\ngit clone https:\/\/github.com\/google\/ngx_brotli.git\ncd ngx_brotli\ngit submodule update --init\nunset https_proxy<\/code><\/pre>\n\n\n\n<p>*nginx&nbsp; \u81ea1.9.11\u4ee5\u540e\u7248\u672c\u540e\u652f\u6301\u52a8\u6001\u6a21\u5757\uff0c\u81ea\u6b64\uff0c\u7ed9nginx\u6dfb\u52a0\u6a21\u5757\u518d\u4e5f\u4e0d\u7528\u91cd\u65b0\u7f16\u8bd1nginx\u4e86\uff0c\u901a\u8fc7\u52a8\u6001\u6a21\u5757\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u6709\u6709\u9009\u62e9\u6027\u7684\u52a0\u8f7d\u7b2c\u4e09\u65b9\u6216Nginx\u5b98\u65b9\u6a21\u5757\u3002<\/p>\n\n\n\n<p>2\u3001\u83b7\u53d6nginx<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/nginx.org\/download\/nginx-1.27.1.tar.gz<\/code><\/pre>\n\n\n\n<p>3\u3001\u52a8\u6001\u5b89\u88c5brotli\u6a21\u5757<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar zvxf nginx-1.27.1.tar.gz\ncd nginx-1.27.1\n.\/configure --with-compat --add-dynamic-module=..\/ngx_brotli\nmake modules\ncp objs\/ngx_http_brotli_filter_module.so objs\/ngx_http_brotli_static_module.so \/opt\/nginx\/modules\/<\/code><\/pre>\n\n\n\n<p>4\u3001add the load_module directives to nginx.conf (above the http block):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>load_module modules\/ngx_http_brotli_filter_module.so;\nload_module modules\/ngx_http_brotli_static_module.so;<\/code><\/pre>\n\n\n\n<p>5\u3001\u542f\u7528brotli\u538b\u7f29\uff08http {&#8230;}\uff09:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    gzip off;\n    brotli on;\n    brotli_static on;\n    brotli_comp_level 11;    (0-11)\n    brotli_min_length 20;\n    brotli_buffers 16 8k;\n    brotli_types *;<\/code><\/pre>\n\n\n\n<p>6\u3001\u53d8\u91cf$brotli_ratio\u53ef\u6253\u5370\u5230access_log\u4e2d<\/p>\n\n\n\n<p>\u5b9e\u73b0\u7684\u538b\u7f29\u7387\uff0c\u4ee5\u539f\u59cb\u54cd\u5e94\u5927\u5c0f\u4e0e\u538b\u7f29\u540e\u54cd\u5e94\u5927\u5c0f\u4e4b\u6bd4\u8ba1\u7b97\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"434\" src=\"https:\/\/opshub.com.cn\/wp-content\/uploads\/2026\/01\/Image-115.png\" alt=\"\" class=\"wp-image-514\" srcset=\"https:\/\/opshub.com.cn\/wp-content\/uploads\/2026\/01\/Image-115.png 671w, https:\/\/opshub.com.cn\/wp-content\/uploads\/2026\/01\/Image-115-300x194.png 300w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><\/figure>\n\n\n\n<p>*nginx: [warn] the &#8220;listen &#8230; http2&#8221; directive is deprecated, use the &#8220;http2&#8221; directive instead<\/p>\n\n\n\n<p>\u628alisten 8080 ssl http2;<\/p>\n\n\n\n<p>\u8c03\u6574\u4e3a\uff1a<\/p>\n\n\n\n<p>listen 8080 ssl;<\/p>\n\n\n\n<p>http2 on;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brotli \u662f\u57fa\u4e8eLZ77\u7b97\u6cd5\u7684\u4e00\u4e2a\u73b0\u4ee3\u53d8\u4f53\u3001\u970d\u592b\u66fc\u7f16\u7801\u3002 Google\u8f6f\u4ef6\u5de5\u7a0b\u5e08 \u57282015\u5e749\u6708\u53d1\u5e03\u4e86\u5305\u542b\u901a\u7528\u65e0\u635f\u6570\u636e\u538b\u7f29\u7684Brotli\u589e\u5f3a\u7248\u672c\uff0c\u7279\u522b\u4fa7\u91cd\u4e8eHTTP\u538b\u7f29\u3002 \u6ce8\u610f\uff1a\u4f7f\u7528\u7b97\u6cd5\u7684\u524d\u63d0\u662f\u542f\u7528\u4e86 https\uff0c\u56e0\u4e3a\u00a0http \u8bf7\u6c42\u4e2d\u00a0request header\u00a0\u91cc\u7684\u00a0Accept-Encoding: gzip, deflate\u00a0\u662f\u6ca1\u6709 br \u7684\u3002 1\u3001\u83b7\u53d6brotli\u6a21\u5757 *nginx&nbsp; \u81ea1.9.11\u4ee5\u540e\u7248\u672c\u540e\u652f\u6301\u52a8\u6001\u6a21\u5757\uff0c\u81ea\u6b64\uff0c\u7ed9nginx\u6dfb\u52a0\u6a21\u5757\u518d\u4e5f\u4e0d\u7528\u91cd\u65b0\u7f16\u8bd1nginx\u4e86\uff0c\u901a\u8fc7\u52a8\u6001\u6a21\u5757\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u6709\u6709\u9009\u62e9\u6027\u7684\u52a0\u8f7d\u7b2c\u4e09\u65b9\u6216Nginx\u5b98\u65b9\u6a21\u5757\u3002 2\u3001\u83b7\u53d6nginx 3\u3001\u52a8\u6001\u5b89\u88c5brotli\u6a21\u5757 4\u3001add the load_module directives to nginx.conf (above the http block): 5\u3001\u542f\u7528brotli\u538b\u7f29\uff08http {&#8230;}\uff09: 6\u3001\u53d8\u91cf$brotli_ratio\u53ef\u6253\u5370\u5230access_log\u4e2d \u5b9e\u73b0\u7684\u538b\u7f29\u7387\uff0c\u4ee5\u539f\u59cb\u54cd\u5e94\u5927\u5c0f\u4e0e\u538b\u7f29\u540e\u54cd\u5e94\u5927\u5c0f\u4e4b\u6bd4\u8ba1\u7b97\u3002 *nginx: [warn] the &#8220;listen &#8230; http2&#8221; directive is deprecated, use the &#8220;http2&#8221; directive instead \u628alisten 8080 ssl http2; \u8c03\u6574\u4e3a\uff1a listen 8080 ssl; http2 on;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-513","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=513"}],"version-history":[{"count":2,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/513\/revisions"}],"predecessor-version":[{"id":602,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/513\/revisions\/602"}],"wp:attachment":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}