Apache网页压缩、缓存、隐藏版本号配置防盗链

  • 配置网页压缩
    检查apache是否安装deflate模块,如果没有就安装
    [root@centos01 ~]# apachectl -t -D DUMP_MODULES |grep deflate
    在这里插入图片描述
  • 配置添加deflate模块,安装依赖软件
    [root@centos01 ~]# yum -y install zlib-devel
    [root@centos01 ~]# cd /usr/src/httpd-2.2.17/
    [root@centos01 httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --enable-deflate --enable-expires
    安装apache
    [root@centos01 httpd-2.2.17]# make && make install
    安装完之后再次检查
    在这里插入图片描述
  • 修改apache主配置文件添加支持压缩功能,最后一行添加
[root@centos01 ~]# vim /usr/local/httpd/conf/httpd.conf
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
DeflateCompressionLevel 9
SetOutputFilter DEFLATE

重新启动apache服务
[root@centos01 ~]# systemctl restart httpd
在这里插入图片描述

  • 配置缓存
    检查是否添加缓存模块,没有的话就添加模块
    [root@centos01 ~]# apachectl -t -D DUMP_MODULES |grep expires
    在这里插入图片描述
    添加缓存模块—enable-expires
    [root@centos01 ~]# cd /usr/src/httpd-2.2.17/
    [root@centos01 httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --enable-deflate --enable-expires
    安装apache
    [root@centos01 httpd-2.2.17]# make && make install
    安装完之后再次检查
    在这里插入图片描述
    修改主配置文件支持缓存功能,最后一行添加
[root@centos01 ~]# vim /usr/local/httpd/conf/httpd.conf
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 60 seconds"
</IfModule>

重新启动apache服务
[root@centos01 ~]# systemctl restart httpd

在这里插入图片描述

  • 隐藏Apache版本号
    修改主配置文件支持隐藏版本功能
    407 Include conf/extra/httpd-default.conf
    修改主配置文件隐藏apache版本号
[root@centos01 ~]# vim /usr/local/httpd/conf/extra/httpd-default.conf
55 ServerTokens Prod
65 ServerSignature Off

重新启动apache服务
[root@centos01 ~]# systemctl restart httpd
在这里插入图片描述

  • 配置防盗链
    Rz上传图片到网站根目录
    [root@centos01 ~]# cd /usr/local/httpd/htdocs/
    在这里插入图片描述
    修改apache主配置文件
修改apache主配置文件
<Directory "/usr/local/httpd/htdocs">
        RewriteEngine On
        RewriteCond %{HTTP_REFERER} !^http://benet.com/.*$[NC]
        RewriteCond %{HTTP_REFERER} !^http://benet.com/$[NC]
        RewriteCond %{HTTP_REFERER} !^http://www.benet.com/.*$[NC]
        RewriteCond %{HTTP_REFERER} !^http://www.benet.com/$[NC]
        RewriteRule .*\.(gif|jpg|swf) $http://www.benet.com/error.html[R,NC]

重新启动apache服务

[root@centos01 ~]# systemctl restart httpd

第二台centos7安装apache服务,启动服务并设置为开机自动启动

yum -y install httpd
systemctl start httpd
systemctl enable httpd

添加盗用第一台服务网站内容

vim /var/www/html/index.html
<html>
        <head>
                <title>test</title>
        </head>
        <body>
                <img src="http://www.benet.com/text.jpg" />
        </body>
</html>

在这里插入图片描述
重新启动apache服务
[root@centos02 ~]# systemctl restart httpd
配置完成以后就盗用不了
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值