apache安装mod_deflate配置支持gzip
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的更多相关文章
- windows Apache 环境下配置支持HTTPS的SSL证书
windows Apache 环境下配置支持HTTPS的SSL证书 1.准备工作 1)在设置Apache + SSL之前, 需要做: 安装Apache, 下载安装Apache时请下载带有SSL版本的A ...
- 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(二):Apache安装和配置
基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...
- [转]:Ubuntu 下Apache安装和配置
[转]:Ubuntu 下Apache安装和配置_服务器应用_Linux公社-Linux系统门户网站 https://www.linuxidc.com/Linux/2013-06/85827.htm ...
- Apache安装及配置ssl
目录 1.windows安装 软件准备 安装apache 开启ssl(Https访问) 打开httpd.conf,解除下面配置的注释 查看ssl模块使用哪一个配置文件 配置https虚拟主机 简单配置 ...
- Ubuntu 下Apache安装和配置
在Ubuntu上安装Apache,有两种方式:1 使用开发包的打包服务,例如使用apt-get命令:2 从源码构建Apache.本文章将详细描述这两种不同的安装方式. 方法一:使用开发包的打包服务—— ...
- (2)apache安装、配置及使用
一.apache安装 假设我们我们的安装路径是 C:\Apache2.2 运行软件 如果是本地学习使用 第二行服务名localhost 其他随便 一个自动安装,一个自定义安装,没有什么特别重要的,一直 ...
- apache 安装及配置
近期想用apache运行网站,在网上查询windows 版本的中文说明文档有特别少,所以将学习到的在这里做个笔记,以便日后学习以及大家相互交流. 相关文档:http://httpd.apache.or ...
- nginx安装及配置支持php的教程(全)
本文的实验环境为:Centos4.5,nginx版本为:nginx-0.7.26 pcre-7.8.tar.gz 正则表达式下载地址:ftp://ftp.csx.cam.ac.uk/pub/so ...
- Apache和Nginx配置支持苹果ATS方法
什么是ATS功能? ATS是iOS9和OS X El Capitan的一个新特性.开启该功能后,ATS对使用NSURLConnection, CFURL或NSURLSession 等APIs 进行的网 ...
随机推荐
- Java处理Excel整理篇
常用Excel,每次写的时候都得现查,索性做一个整理. Java里用的时候一般用jxl这个包,相对好用. 读: File file = new File(excelFile);Workbook boo ...
- iOS"Request failed: unacceptable content-type: text/html"
接口访问出错了,用浏览器测试,发现可以正常返回数据. 下面是错误信息: 获取服务器响应出错 error=Error Domain=com.alamofire.error.serialization.r ...
- 形象的讲解angular中的$q与promise(转)
以下内容摘自http://www.ngnice.com/posts/126ee9cf6ddb68 promise不是angular首创的,作为一种编程模式,它出现在……1976年,比js还要古老得多. ...
- wpf 遮住输入法 问题
可以参考这个代码 http://www.cnblogs.com/Leaco/p/3164394.html 当你发现没用的时候 可以改这句代码 var hwnd = ((HwndSource)Pr ...
- 使用SeasLog打造PHP项目中的高性能日志组件(一)
云智慧(北京)科技有限公司 高驰涛 什么是SeasLog SeasLog是一个C语言编写的PHP扩展,提供一组规范标准的功能函数,在PHP项目中方便.规范.高效地写日志,以及快速地读取和查询日志. 为 ...
- Versioned table in Netezza
Problem One QC process need to obtain tables and their row counts in a database in Netezza. We use t ...
- thinkphp 验证
//YongHuModel.class.php namespace Home\Model; use Think\Model; class YongHuModel exstends Model { pr ...
- JAVA 中数据库连接的方法之一
/** * 数据库连接类 * */ package com.cn.MysqlConnect; import java.sql.Connection;import java.sql.DriverMana ...
- Oracle学习线路
出自huyangg的博客,地址是:oracle学习路线图 1.sql.pl/sql(网上有很多的视频,可以做一个简单的入手,然后看几本书,多做实验) 作为oracle的基本功,需要大家对sql和 ...
- SQL Server 查询表备注信息的语句
--name 字段名称--user_type_id --max_length 最大长度--is_nullable 是否允许空--remark 描述SELECT c.name, c.user_ty ...