启用网页压缩功能步骤
1,查看是否安装mod_deflate模块
2,在配置httpd.conf中配置开启gzip功能
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript '//代表对什么样的内容启用gzip压缩'
DeflateCompressionLevel '//代表压缩级别'
SetOutputFilter DEFLATE '//代表启用deflate模块对本站点的输出进行gzip压缩'
[root@localhost ~]# smbclient -L //192.168.100.3
Enter SAMBA\root's password:
Sharename Type Comment
--------- ---- -------
ADMIN$ Disk 远程管理
C$ Disk 默认共享
ccc Disk
...省略内容
[root@localhost ~]# mount.cifs //192.168.100.3/ccc /mnt
Password for root@//192.168.100.3/ccc:
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
...省略内容
//192.168.100.3/ccc 444G 31G 413G 7% /mnt
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
LAMP-C7 LAMP-C7.rar
[root@localhost mnt]# cd LAMP-C7/
[root@localhost LAMP-C7]# ls
apr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txt php-5.6.11.tar.bz2
apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2 mysql-5.6.26.tar.gz
将跨平台组件包移动到源码包目录下
[root@localhost LAMP-C7]# tar zxvf apr-1.6.2.tar.gz -C /opt
...省略内容
[root@localhost LAMP-C7]# tar zxvf apr-util-1.6.0.tar.gz -C /opt
...省略内容
[root@localhost LAMP-C7]# tar jxvf httpd-2.4.29.tar.bz2 -C /opt
...省略内容
[root@localhost LAMP-C7]# cd /opt
[root@localhost opt]# ls
apr-1.6.2 apr-util-1.6.0 httpd-2.4.29 rh
[root@localhost opt]# mv apr-1.6.2/ httpd-2.4.29/s
server/ srclib/ support/
[root@localhost opt]# mv apr-1.6.2/ httpd-2.4.29/srclib/apr
[root@localhost opt]# mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
[root@localhost opt]# ls httpd-2.4.29/srclib/
apr apr-util Makefile.in
[root@localhost opt]# yum -y install \
> gcc \ '//编译器'
> gcc-c++ \ '//编译器'
> make \ '//make工具'
> pcre-devel \ '//支持正则表达式的工具'
> expat-devel \ '//使网站能解析标签语言的工具'
> perl '//Perl语言工具'
> zlib-devel
...省略内容
[root@localhost opt]# cd httpd-2.4.29/
[root@localhost httpd-2.4.29]# ls
...省略内容
ap.d configure include Makefile.in
...省略内容
[root@localhost httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \ '//指定路径'
> --enable-so \ '//开启核心功能模块'
> --enable-rewrite \ '//开启重写功能,如防盗链保护'
> --enable-charset-lite \ '//开启字符集'
> --enable-cgi \ '//开启通用网关接口'
> --enable-deflate '//开启deflate压缩模块'
...省略内容
[root@localhost httpd-2.4.29]# make '//编译'
...省略内容
[root@localhost httpd-2.4.29]# make install '//安装'
[root@localhost httpd-2.4.29]# cd /usr/local/httpd/conf/
[root@localhost conf]# ls
extra httpd.conf magic mime.types original
[root@localhost conf]# ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf '//创建软链接,可选'
[root@localhost conf]# vim /etc/httpd.conf
'//搜索/deflate,如果没有,则需要检查之前配置并重新编译安装'
LoadModule deflate_module modules/mod_deflate.so '//将此行取消注释'
'//搜索/head和/filter(过滤)是否都在,并在末尾添加以下信息'
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascrip text/jpg text/png
DeflateCompressionLevel 9
SetOutputFilter DEFLATE
'//修改监听地址'
Listen 192.168.197.142:80
#Listen 80
'//取消注释,修改域名'
ServerName www.dabao.com:80
'//使用apachectl工具检查是否配置正确'
[root@localhost conf]# /usr/local/httpd/bin/apachectl -t
Syntax OK
[root@localhost ~]# /usr/local/httpd/bin/apachectl start '//开启服务'
[root@localhost ~]# netstat -ntap |grep 80
tcp 0 0 192.168.197.142:80 0.0.0.0:* LISTEN 117304/httpd
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# cd /usr/local/httpd/
[root@localhost httpd]# ls
bin build cgi-bin conf error htdocs icons include lib logs man manual modules
[root@localhost httpd]# cd htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# cat index.html
It works!
'//查看主页内容'
[root@localhost bin]# ./apachectl -t -D DUMP_MODULES |grep "deflate" '//查看是否安装mod_deflate模块'
deflate_module (shared)
[root@localhost ~]# mount.cifs //192.168.100.3/ccc /mnt
Password for root@//192.168.100.3/ccc:
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
aaa.jpg awstats-7.6.tar.gz httpd-2.4.2.tar.gz
apr-1.4.6.tar.gz cronolog-1.6.2-14.el7.x86_64.rpm LAMP-C7
apr-util-1.4.1.tar.gz fiddler.exe LAMP-C7.rar
[root@localhost mnt]# cp aaa.jpg /usr/local/httpd/
bin/ cgi-bin/ error/ icons/ lib/ man/ modules/
build/ conf/ htdocs/ include/ logs/ manual/
[root@localhost mnt]# cp aaa.jpg /usr/local/httpd/htdocs/
[root@localhost mnt]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
aaa.jpg index.html
[root@localhost htdocs]# vim index.html
It works!
"aaa.jpg"/> '//添加一张图片'
Windows主机验证
方法同上操作,直接刷新查看
查看是否安装mod_expire模块
/usr/local/apache/bin/apachectl -t -D DUMP_MODULES
如果输出中没有expires_module(static),则说明编译时没有安装 mod_expires
若没有安装则需要重新编译安装
修改httpd.conf配置文件
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 60 seconds"
</IfModule>
重启httpd服务
再次访问测试网站,使用抓包工具Fiddler进行数据抓取分析
[root@localhost httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \
> --enable-so \
> --enable-rewrite \
> --enable-charset-lite \
> --enable-cgi \
> --enable-deflate \
> --enable-expires
[root@localhost httpd-2.4.29]# make
[root@localhost httpd-2.4.29]# make install
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf '//建软链接便于管理'
[root@localhost httpd-2.4.29]# vim /etc/httpd.conf
ServerName www.dabao.com:80 '//修改域名'
Listen 192.168.197.143:80 '//修改监听地址'
#Listen 80
LoadModule expires_module modules/mod_expires.so '//开启缓存模块'
'//下面验证语法格式'
[root@localhost httpd-2.4.29]# pwd
/opt/httpd-2.4.29
[root@localhost httpd-2.4.29]# cd /usr/local/httpd/
[root@localhost httpd]# ls
bin build cgi-bin conf error htdocs icons include lib logs man manual modules
[root@localhost httpd]# cd bin
[root@localhost bin]# ./apachectl -t
Syntax OK '//语法格式没问题'
'//检测expires模块'
[root@localhost bin]# ./apachectl -t -D DUMP_MODULES | grep "expires"
expires_module (shared)
[root@localhost bin]# ./apachectl start
[root@localhost bin]# netstat -ntap |grep 80
tcp 0 0 192.168.197.143:80 0.0.0.0:* LISTEN 72523/httpd
[root@localhost bin]# systemctl stop firewalld.service
[root@localhost bin]# setenforce 0
[root@localhost bin]# vim /etc/httpd.conf
...省略内容
ExpiresActive On
ExpiresDefault "access plus 200 seconds" '//文件末尾,将60秒修改为其他时间,验证'
[root@localhost bin]# ./apachectl stop
[root@localhost bin]# ./apachectl start
规则匹配
规则匹配说明
RewriteEngine On:打开网页重写功能
RewriteCond:设置匹配规则
RewriteRule:设置跳转动作
RewriteEngine On
RewriteCond %{HTTP_REFERER}!^http://test.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://test.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.test.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.test.com$ [NC]
RewriteRule .*\.(gif|jpg|swf)$ http://www.test.com/error.html [R,NC]
[root@localhost httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \
> --enable-so \
> --enable-rewrite \
> --enable-charset-lite \
> --enable-cgi \
> --enable-deflate \
> --enable-expires
[root@localhost httpd-2.4.29]# make
[root@localhost httpd-2.4.29]# make install
[root@localhost bin]# yum install bind -y
[root@localhost bin]# vim /etc/named.conf
options {
listen-on port 53 { any;}; '//修改为any'
...省略内容
allow-query { any; }; '//修改为any'
[root@localhost bin]# vim /etc/named.rfc1912.zones
'//添加以下内容到正向解析中'
zone "dabao.com" IN {
type master;
file "dabao.com.zone";
allow-update { none; };
};
[root@localhost etc]# cp -p /var/named/named.localhost /var/named/dabao.com.zone
[root@localhost etc]# vim /var/named/dabao.com.zone
'//尾行修改为下面内容'
www IN A 192.168.197.143
[root@localhost etc]# systemctl start named
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf '//建软链接便于管理'
[root@localhost httpd-2.4.29]# vim /etc/httpd.conf
ServerName www.dabao.com:80 '//修改域名'
Listen 192.168.197.143:80 '//修改监听地址'
#Listen 80
'//开始修改www.dabao.com主页中添加图片'
[root@localhost mnt]# cp /mnt/aaa.jpg /usr/local/httpd/htdocs/
[root@localhost mnt]# vim /usr/local/httpd/htdocs/index.html
It works!
"aaa.jpg"/>
[root@localhost mnt]# cd /usr/local/httpd/bin
[root@localhost bin]# ./apachectl start
[root@localhost bin]# netstat -ntap |grep 80
tcp 0 0 192.168.197.143:80 0.0.0.0:* LISTEN 121391/httpd
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# echo "nameserver 192.168.197.143" > /etc/resolv.conf
[root@localhost ~]# nslookup www.dabao.com
Server: 192.168.197.143
Address: 192.168.197.143#53
Name: www.dabao.com
Address: 192.168.197.143
[root@localhost ~]# ifconfig
ens33: flags=4163 mtu 1500
inet 192.168.197.141
[root@localhost ~]# vim /var/www/html/index.html
this is daolian web!
"http://www.dabao.com/aaa.jpg"/>
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost bin]# vim /etc/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
'//将以下文字添加到 中'
以下是要添加的内容
RewriteEngine On
RewriteCond % {HTTP_REFERER} !^http://dabao.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://dabao.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.dabao.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.dabao.com$ [NC]
RewriteRule .*\.(gif|jpg|swf)$ http://www.dabao.com/error.png
[root@localhost bin]# cp /mnt/error.png /usr/local/httpd/htdocs/
[root@localhost bin]# cd ..
[root@localhost httpd]# cd htdocs/
[root@localhost htdocs]# ls
aaa.jpg error.png index.html
[root@localhost htdocs]# cd ..
[root@localhost bin]# ./apachectl stop
[root@localhost bin]# ./apachectl start
[root@localhost httpd]# cd conf/extra
[root@localhost extra]# vim httpd-default.conf
'//将以下内容修改'
Include conf/extra/httpd-default.conf '//开启,取消注释'
ServerTokens Prod '//将原本的Full修改为Prod
ServerSignature Off '//保持是Off'
[root@localhost conf]# cd /usr/local/httpd/bin
[root@localhost bin]# ./apachectl stop
[root@localhost bin]# ./apachectl start