Apache压缩实现网页压缩的功能模块有mod_gzip模块,mod_deflate模块,Apache 1.x,没有内建网页压缩技术,但可使用第三方mod_gzip模块执行压缩,Apache 2.x,在开发的时候,内建了mod_deflate这个模块,取代mod_gzip。
Apache缓存通过mod_expire模块配置Apache,使网页在客户端浏览器缓存一段时间,以避免重复请求。启用mod_expire模块之后,会自动生成页面头部信息中的expire标签和Cache-control标签,从而降低客户端的访问频率和次数,达到减少不必要的流量和增加访问速度的目的。
yum install -y \
> gcc \
> gcc-c++ \
> make \
> pcre-devel \
> expat-devel \
> perl
yum install -y zlib-devel #######安装压缩软件
cd httpd-2.4.29/
./configure \
> --prefix=/usr/local/httpd \
> --enable-so \
> --enable-rewrite \
> --enable-charset-lite \
> --enable-cig \
> --enable-deflate #######比起手工编译安装多一个deflate模块
make && make install
ln -s /usr/local/httpd/conf/httpd.conf /etc ########给配置文件创建软连接方便操作
vim /etc/httpd.conf
############开启三个模块#############################
LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so
##########在最末行添加deflate模块的控制字段#############
AddOutputFilterByType DEFLATE text/html text/plain test/css text/xml text/javascript text/jpg text/png
DeflateCompressionLevel 9
SetOutputFilter DEFLATE
/usr/local/httpd/bin/httpd -t
Syntax OK
#########相当于systemctl start httpd#########
/usr/local/httpd/bin/httpd
#####################验证模块###########
/usr/local/httpd/bin/httpd -t -D DUMP_MODULES |grep "deflate"
deflate_module (shared)
##################或者##############################
cd /usr/local/httpd/bin/
./apachectl -t -D DUMP_MODULES |grep "deflate"
deflate_module (shared)
cd /usr/local/httpd/htdocs/
使用抓包工具在headers中图片是gzip压缩格式
yum install -y \
> gcc \
> gcc-c++ \
> make \
> pcre-devel \
> expat-devel \
> perl \
>zlib-devel
cd httpd-2.4.29/
./configure \
> --prefix=/usr/local/httpd \
> --enable-so \
> --enable-rewrite \
> --enable-charset-lite \
> --enable-cig \
> --enable-deflate \ #######比起手工编译安装多一个deflate模块
> --enable-expires ###########缓存模块
make && make install
ln -s /usr/local/httpd/conf/httpd.conf /etc ########给配置文件创建软连接方便操作
LoadModule expires_module modules/mod_expires.so
###########在配置文件中的末尾添加##########
ExpiresActive On
ExpiresDefault "access plus 50 seconds"
/usr/local/httpd/bin/httpd -t
Syntax OK
cd /usr/local/httpd/htdocs/
/usr/local/httpd/bin/httpd
/usr/local/httpd/bin/httpd -t -D DUMP_MODULES |grep "deflate"
deflate_module (shared)
##################或者##############################
cd /usr/local/httpd/bin/
./apachectl -t -D DUMP_MODULES |grep "expires"
deflate_module (shared)
在headers中会有expires
防盗链是防止别人的网站代码里面盗用我们自己服务器上的图片文件视频等相关资源,如果别人盗用网站的这些静态资源,明显的是会增大服务器的带宽压力,作为网站的维护人员,要杜绝服务器的静态资源被其他网站盗用。至于隐藏版本号是别人访问到的网页无法显示服务的版本号。
yum install -y \
> gcc \
> gcc-c++ \
> make \
> pcre-devel \
> expat-devel \
> perl \
>zlib-devel
cd httpd-2.4.29/
./configure \
> --prefix=/usr/local/httpd \
> --enable-so \
> --enable-rewrite \
> --enable-charset-lite \
> --enable-cig \
> --enable-deflate
make && make install
ln -s /usr/local/httpd/conf/httpd.conf /etc ########给配置文件创建软连接方便操作
vim /etc/httpd.conf #########修改配置文件域名和监听端口
Listen 192.168.60.10:80
ServerName www.example.com:80
cd /usr/local/httpd/htdocs/
ls
error.jpg(防盗链开启之后的页面) index.html meinv.jpg(需要访问的页面)
vim index.html
It works!
/usr/local/httpd/bin/apachectl start
vim /var/www/html/index.html
this is esha from daolian
###########盗链##########
systemctl start httpd
#################就可以使用另一台服务器的IP192.168.60.60访问192.168.60.10配置的网页。
vim /etc/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so###########开启防盗链模块
DocumentRoot "/usr/local/httpd/htdocs"
Require all granted
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://192.168.60.10/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://192.168.60.10$ [NC]
RewriteCond %{HTTP_REFERER} !^http://192.168.60.10/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://192.168.60.10/$ [NC]
RewriteRule .*\.(gif|png|swf)$ http://192.168.60.10/error.jpg
/usr/local/httpd/bin/apachectl restart
systemctl restart httpd.service
这样访问盗链服务器时显示的是error图片
Server:Apache2.4.29(Linux)
vim /etc/httpd.conf
Include conf/extra/httpd-default.conf
vim /usr/local/httpd/conf/extra/httpd-default.conf
ServerTokens Prod
/usr/local/httpd/bin/apachectl restart
使用抓包工具查看信息
Server:Apache