apache 配置支持gzip

apache使用gzip压缩能够大幅提高网站访问速度并节省网络流量,在网页响应头信息中可以判断是否支持压缩。


HTTP/1.1 200 OK

Date: Wed, 14 Dec 2016 04:33:08 GMT

Content-Type: text/html; charset=utf-8

Transfer-Encoding: chunked

Connection: keep-alive

Vary: Accept-Encoding

Cache-Control: private, max-age=10

Expires: Wed, 14 Dec 2016 04:33:18 GMT

Last-Modified: Wed, 14 Dec 2016 04:33:08 GMT

X-UA-Compatible: IE=10

Content-Encoding: gzip


1.安装动态库

gzip需要mod_deflate.so和mod_headers.so, 但是不像系统自带的apache,后来安装的apache是没有带这些库的。如果自带库,请直接跳到第二步。

[hubery@localhost ~]$ ls -l /etc/httpd/modules/
total 5140
-rwxr-xr-x 1 root root 3699056 8月 12 04:36 libphp5.so
...
-rwxr-xr-x 1 root root 27056 11月 19 07:49 mod_deflate.so
-rwxr-xr-x 1 root root 10416 11月 19 07:49 mod_dir.so
-rwxr-xr-x 1 root root 22992 11月 19 07:49 mod_disk_cache.so
-rwxr-xr-x 1 root root 10448 11月 19 07:49 mod_dumpio.so
-rwxr-xr-x 1 root root 10416 11月 19 07:49 mod_env.so
-rwxr-xr-x 1 root root 10512 11月 19 07:49 mod_expires.so
-rwxr-xr-x 1 root root 23120 11月 19 07:49 mod_ext_filter.so
-rwxr-xr-x 1 root root 18736 11月 19 07:49 mod_filter.so
-rwxr-xr-x 1 root root 22992 11月 19 07:49 mod_headers.so
... [hubery@localhost ~]$ ls /usr/local/apache2/modules/
httpd.exp libphp5.so mod_deflate.so mod_headers.so
安装mod_headers
[root@localhost metadata]# pwd
/home/hubery/httpd-2.2.29/modules/metadata
[root@localhost metadata]# /usr/local/apache2/bin/apxs -i -a -c mod_headers.c
/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/apache2/include -c -o mod_headers.lo mod_headers.c && touch mod_headers.slo
/usr/local/apache2/build/libtool --silent --mode=link gcc -o mod_headers.la -rpath /usr/local/apache2/modules -module -avoid-version mod_headers.lo
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' mod_headers.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool --mode=install cp mod_headers.la /usr/local/apache2/modules/
cp .libs/mod_headers.so /usr/local/apache2/modules/mod_headers.so
cp .libs/mod_headers.lai /usr/local/apache2/modules/mod_headers.la
cp .libs/mod_headers.a /usr/local/apache2/modules/mod_headers.a
chmod 644 /usr/local/apache2/modules/mod_headers.a
ranlib /usr/local/apache2/modules/mod_headers.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/apache2/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/apache2/modules If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache2/modules/mod_headers.so
[activating module `headers' in /usr/local/apache2/conf/httpd.conf]
安装mod_deflate
[root@localhost filters]# pwd
/home/hubery/httpd-2.2.29/modules/filters
[root@localhost filters]# /usr/local/apache2/bin/apxs -i -c -a mod_deflate.c
/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/apache2/include -c -o mod_deflate.lo mod_deflate.c && touch mod_deflate.slo
/usr/local/apache2/build/libtool --silent --mode=link gcc -o mod_deflate.la -rpath /usr/local/apache2/modules -module -avoid-version mod_deflate.lo
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' mod_deflate.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool --mode=install cp mod_deflate.la /usr/local/apache2/modules/
cp .libs/mod_deflate.so /usr/local/apache2/modules/mod_deflate.so
cp .libs/mod_deflate.lai /usr/local/apache2/modules/mod_deflate.la
cp .libs/mod_deflate.a /usr/local/apache2/modules/mod_deflate.a
chmod 644 /usr/local/apache2/modules/mod_deflate.a
ranlib /usr/local/apache2/modules/mod_deflate.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/apache2/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/apache2/modules If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache2/modules/mod_deflate.so
[activating module `deflate' in /usr/local/apache2/conf/httpd.conf]

2.配置支持

去掉注释或添加下面两段。
[hubery@localhost ~]$ cat /usr/local/apache2/conf/httpd.conf
#...
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
#...
<Location />
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE text/html
</Location>
#...
重启apache2

[hubery@localhost ~]$ sudo /usr/local/apache2/bin/httpd -k restart

检查模块是否加载
[hubery@localhost ~]$ /usr/local/apache2/bin/apachectl -t -D DUMP_MODULES
Loaded Modules:
core_module (static)
authn_file_module (static)
authn_default_module (static)
authz_host_module (static)
authz_groupfile_module (static)
authz_user_module (static)
authz_default_module (static)
auth_basic_module (static)
include_module (static)
filter_module (static)
log_config_module (static)
env_module (static)
setenvif_module (static)
version_module (static)
ssl_module (static)
mpm_prefork_module (static)
http_module (static)
mime_module (static)
status_module (static)
autoindex_module (static)
asis_module (static)
cgi_module (static)
negotiation_module (static)
dir_module (static)
actions_module (static)
userdir_module (static)
alias_module (static)
rewrite_module (static)
so_module (static)
php5_module (shared)
deflate_module (shared)
headers_module (shared)
Syntax OK

参考:

CentOS Apache 如何开启 Gzip 开启

linux下apache安装gzip压缩(Deflate模块)

apache安装mod_deflate配置支持gzip的更多相关文章

  1. windows Apache 环境下配置支持HTTPS的SSL证书

    windows Apache 环境下配置支持HTTPS的SSL证书 1.准备工作 1)在设置Apache + SSL之前, 需要做: 安装Apache, 下载安装Apache时请下载带有SSL版本的A ...

  2. 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(二):Apache安装和配置

    基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...

  3. [转]:Ubuntu 下Apache安装和配置

    [转]:Ubuntu 下Apache安装和配置_服务器应用_Linux公社-Linux系统门户网站  https://www.linuxidc.com/Linux/2013-06/85827.htm ...

  4. Apache安装及配置ssl

    目录 1.windows安装 软件准备 安装apache 开启ssl(Https访问) 打开httpd.conf,解除下面配置的注释 查看ssl模块使用哪一个配置文件 配置https虚拟主机 简单配置 ...

  5. Ubuntu 下Apache安装和配置

    在Ubuntu上安装Apache,有两种方式:1 使用开发包的打包服务,例如使用apt-get命令:2 从源码构建Apache.本文章将详细描述这两种不同的安装方式. 方法一:使用开发包的打包服务—— ...

  6. (2)apache安装、配置及使用

    一.apache安装 假设我们我们的安装路径是 C:\Apache2.2 运行软件 如果是本地学习使用 第二行服务名localhost 其他随便 一个自动安装,一个自定义安装,没有什么特别重要的,一直 ...

  7. apache 安装及配置

    近期想用apache运行网站,在网上查询windows 版本的中文说明文档有特别少,所以将学习到的在这里做个笔记,以便日后学习以及大家相互交流. 相关文档:http://httpd.apache.or ...

  8. nginx安装及配置支持php的教程(全)

    本文的实验环境为:Centos4.5,nginx版本为:nginx-0.7.26   pcre-7.8.tar.gz  正则表达式下载地址:ftp://ftp.csx.cam.ac.uk/pub/so ...

  9. Apache和Nginx配置支持苹果ATS方法

    什么是ATS功能? ATS是iOS9和OS X El Capitan的一个新特性.开启该功能后,ATS对使用NSURLConnection, CFURL或NSURLSession 等APIs 进行的网 ...

随机推荐

  1. [delphi]运行cmd命令,并取得输出字符

     http://blog.csdn.net/nerdy/article/details/8969189 [delphi]运行cmd命令,并取得输出字符 标签: delphiCMD命令 2013-05- ...

  2. 史航416第11次作业&总结

    作业1:冒泡排序 #include <stdio.h> ],int n); int main() { ],n,i; printf("输入一个整数n:"); scanf( ...

  3. 常见绘图框架-(Charts)

    swift 出来后有很多优秀的第三方绘图.动画框架,最近项目需要使用了 Charts Github: https://github.com/danielgindi/Charts 因为是在Object- ...

  4. Centos 7U盘安装

    1. 8G U盘 老毛桃软件 centos 7 everything.iso 7.4G左右 2.遇到问题 安装一刚开始 报错 unexpected exception  attribute error ...

  5. Direct2D相关

    1,如何绘制文本 2,文本格式设置和布局

  6. linux grep -I 属性

    忽略大小写的查找: grep -i 'address' test.log --> address ADDRESS

  7. Java 内存溢出(java.lang.OutOfMemoryError)的常见情况和处理方式总结

    最近老是遇见服务器内存溢出的问题,故在网上搜了搜,总结了一些java内存溢出的解决方式 java.lang.OutOfMemoryError这个错误我相信大部分开发人员都有遇到过,产生该错误的原因大都 ...

  8. 把HBITMAP 保存图片文件.

    //VC下把HBITMAP保存为bmp图片 BOOL CtestBitMapDlg::SaveBmp(HBITMAP hBitmap, CString FileName) { HDC hDC; //当 ...

  9. [转]VS2013自带SQL Server 的启用方法

    本文转自:http://www.icharm.me/vs2013%E8%87%AA%E5%B8%A6%E7%9A%84%E6%95%B0%E6%8D%AE%E5%BA%93sql-server-exp ...

  10. [刘阳Java]_快速搭建MyBatis环境_第2讲

    1.MyBatis的环境配置 导入MyBatis包, mybatis-3.2.8.jar 导入MySQL驱动包, mysql-connector-java-5.1.24-bin.jar 创建表的实体类 ...