当前位置:首页 > 服务器 > 正文

服务器开启gzip压缩(gzip命令压缩文件夹)

本篇文章给大家谈谈服务器开启gzip压缩,以及gzip命令压缩文件夹对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

nginx开启gzip

nginx实现资源压缩的原理是通过ngx_http_gzip_module模块拦截请求,并对需要做gzip的类型做gzip压缩,该模块是默认基础的,不需要重新编译,直接开启即可。

1.nginx的response headers中的Content-Encoding是gzip

2.返回文件大小明显被压缩

1.直接在浏览器通过开发者工具查看请求头、返回头等信息

2.使用curl命令行curl -I -H"Accept-Encoding: gzip, deflate" " "

3.站长工具中的 网页Gzip检测

1.先检查gzip_types中是否包含需要的类型

2.如果公司存在多层缓存机制,确认每一层都开启了gzip压缩

3.开启 gzip_static on,确认服务器上是否存在.gz文件

教你开启apache服务器gzip压缩配置的操作方法

实现操作

1、找到并打开apache/conf目录中的httpd.conf文件

2、httpd.conf中打开deflate_Module和headers_Module模块,具体做法为将

如下两句前面的#去掉:

LoadModule

deflate_module

modules/mod_deflate.so

LoadModule

headers_module

modules/mod_headers.so

3、在httpd.conf文件底部加入如下代码配置需要压缩的文件类型:

IfModule

deflate_moduleSetOutputFilter

DEFLATE#

Don’t

compress

images

and

otherSetEnvIfNoCase

Request_URI

.(?:gif|jpe?g|png)$

no-gzip

dont-varySetEnvIfNoCase

Request_URI

.(?:exe|t?gz|zip|bz2|sit|rar)$

no-gzip

dont-varySetEnvIfNoCase

Request_URI

.(?:pdf|doc)$

no-gzip

dont-varyAddOutputFilterByType

DEFLATE

text/html

text/plain

text/xml

text/cssAddOutputFilterByType

DEFLATE

application/x-javascript/IfModule

4、重启apache服务端

5、使用站长工具查看是否已经开启。

Nginx开启和配置Gzip压缩

nginx 是一个高性能的 Web 服务器,合理配置nginx可以有效提高网站的响应速度。

本文介绍 nginx 的 gzip 和缓存开启配置。

gzip的压缩页面需要浏览器和服务器双方都支持,实际上就是服务器端压缩,传到浏览器后浏览器解压并解析。

Nginx的压缩输出有一组gzip压缩指令来实现。

相关指令位于 http{…} 两个大括号之间。

pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 14px; margin-top: 0px; margin-bottom: 1rem; overflow: auto; display: block; color: rgb(33, 37, 41); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"# 开启gzip

gzip on;

gzip_min_length 1k;

gzip_comp_level 6;

gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

gzip_vary on;

gzip_disable "MSIE [1-6].";/pre

关于具体的参数说明可以参考 nginx 的文档 。

pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 14px; margin-top: 0px; margin-bottom: 1rem; overflow: auto; display: block; color: rgb(33, 37, 41); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"location ~* ^.+.(ico|gif|jpg|jpeg|png)$ {

access_log off;

expires 30d;

}

location ~* ^.+.(css|js|txt|xml|swf|wav)$ {

access_log off;

expires 24h;

}

location ~* ^.+.(html|htm)$ {

expires 1h;

}/pre

其中的缓存时间可以自己根据需要修改。

关于服务器开启gzip压缩和gzip命令压缩文件夹的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

取消
扫码支持 支付码