使用静态 gzip 后,Nginx 速度更快!设置方法和压缩方法说明
<p><strong>用gzip静态加速!</strong></p>
<p>这绝对是你应该做的事情。<br />
并不是特别麻烦,而且效果也很突出。</p>
<p>这解释了 <a class="wpal-linked-keyword" href="https://nginx.p2hp.com/" target="_blank">Nginx</a> 中的 gzip_static。<span id="more-11783"></span></p>
<div id="toc">
<div class="mokuji">目录</div>
<div id="mokuji-list">
<ol>
<li><a class="mokuji-a" href="https://doudonn.com/saba/2331/#heading1" target="_blank" rel="nofollow noopener">1.不使用gzip static时的gzip处理</a></li>
<li><a class="mokuji-a" href="https://doudonn.com/saba/2331/#heading2" target="_blank" rel="nofollow noopener">2.使用gzip static时的gzip处理</a></li>
<li><a class="mokuji-a" href="https://doudonn.com/saba/2331/#heading3" target="_blank" rel="nofollow noopener">3.使用gzip static的优点</a></li>
<li><a class="mokuji-a" href="https://doudonn.com/saba/2331/#heading4" target="_blank" rel="nofollow noopener">4. 需要一个模块才能在 Nginx 中使用 gzip static</a></li>
<li><a class="mokuji-a" href="https://doudonn.com/saba/2331/#heading5" target="_blank" rel="nofollow noopener">5.如何在Nginx上配置gzip静态</a></li>
<li><a class="mokuji-a" href="https://doudonn.com/saba/2331/#heading6" target="_blank" rel="nofollow noopener">6. 如何使用gzip压缩</a></li>
<li><a class="mokuji-a" href="https://doudonn.com/saba/2331/#heading7" target="_blank" rel="nofollow noopener">7. 需要压缩的文件</a></li>
</ol>
</div>
</div>
<h2 id="heading1">1.不使用gzip static时的gzip处理</h2>
<p><img referrerpolicy="no-referrer" loading="lazy" loading="lazy" class="aligncenter size-full wp-image-11784" src="https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-2.jpg" alt="Nginx 不使用 gzip_static 时 gzip 处理的说明" width="1187" height="615" srcset="https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-2.jpg 1187w, https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-2-300x155.jpg 300w, https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-2-1024x531.jpg 1024w, https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-2-768x398.jpg 768w" sizes="(max-width: 1187px) 100vw, 1187px" /></p>
<p><strong>如果你不使用gzip_static而只是“gzip on”,它每次都会被压缩并发送。</strong></p>
<p>虽然它实际上可能缓存在内存中,但传统<br />
观点是“每次都会执行压缩处理,因此 CPU 负载很大。”<br />
因此,我每次都想停止处理它。</p>
<p>“gzip_static”可以实现这一点。</p>
<h2 id="heading2">2.使用gzip static时的gzip处理</h2>
<p><img referrerpolicy="no-referrer" loading="lazy" loading="lazy" class="aligncenter size-full wp-image-11785" src="https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-1.jpg" alt="Nginx中开启gzip_static时gzip处理的说明" width="1187" height="617" srcset="https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-1.jpg 1187w, https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-1-300x156.jpg 300w, https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-1-1024x532.jpg 1024w, https://blog.p2hp.com/wp-content/uploads/2024/02/p2331-1-768x399.jpg 768w" sizes="(max-width: 1187px) 100vw, 1187px" /></p>
<p><strong>它将搜索“gz”文件并为您使用!</strong></p>
<p>如果是“style.css”,它将自动搜索文件“style.css.gz”。<br />
如果找到,则返回它;如果没有,则照常压缩“style.css”。…</p>
<p>The post <a href="https://blog.p2hp.com/archives/11783">使用静态 gzip 后,Nginx 速度更快!设置方法和压缩方法说明</a> first appeared on <a href="https://blog.p2hp.com">Lenix Blog</a>.</p>