在被盗链的主机(192.168.10.120)设置防盗链规则


<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
RewriteEngine On #启用rewrite
RewriteCond %{HTTP_REFERER} !^*$ #匹配所有非直接访问本机的请求
RewriteCond %{HTTP_REFERER} !^*$
RewriteRule .*\.(gif|swf|jpg)$ [R,NC] #对匹配到的请求进行重定向,返回指定页面或资
</Directory>
#返回的资源类型不能与匹配项相同,否则会陷入循环
#RewriteCond 匹配条件
#RewriteRule 重写规则
#%{HTTP_REFERER} 引导用户代理到当前页的前一页的地址,即用户浏览器直接输入的访问地址
#[NC]指的是不区分大小写,[R]强制重定向redirect
#[L]表示如果能匹配本条规则,那么本条规则是最后一条(Last),忽略之后的规则
重启服务

再次访问盗链主机,查看防盗链效果

访问被盗链主机查看是否受到影响

隐藏Apache版本号
为提高服务器安全性有时会选择将软件的版本号隐藏
修改主配置文件


ServerTokens Prod #返回的头部信息中版本信息
ServerSignature Off
#ServerTokens Major|Minor|Minimal|ProductOnly|OS|Full
#Prod[uctOnly] 只显示服务名-->Server:Apache
#Major 服务/主版本号 Server:Apache/2
#Minor 服务/主版本号.次版本号 Server:Apache/2.4
#Min[imal] 服务/主版本号.次版本号.末版本号 Server:Apache/2.4.6
#Min[imal] 服务/主版本号.次版本号.末版本号(系统类型) Server:Apache/2.4.6(CentOS)
#Full 显示全部相关信息
#ServerSignature 控制由系统生成的页面(错误信息,mod_proxy ftp directory listing等等)的页脚中如何显示信息
#注设置需要声明在全局配置中
重启服务

测试
关闭前响应头部信息

关闭后响应头部信息

虚拟主机配置
httpd2.4的虚拟主机配置文件为: /etc/httpd/conf.d/vhost.conf (缺省下不存在)
httpd2.4 的虚拟主机不再需要NameVirtualHost 参数开启
创建并修改vhost.conf文件


<VirtualHost 192.168.10.120:80> #指定虚拟主机
ServerAdmin root@web1.lg.com #管理邮箱地址
DocumentRoot /www/docs/web1 #站点根目录
<Directory "/www/docs/web1"> #权限控制
AllowOverride None #是否允许权限覆盖
Options Indexes #使用的选项参数 Indexs若无匹配的主页则列表显示站点目录内容
Require all granted #允许全部
</Directory>
ServerName web1.lg.com #站点域名
ErrorLog logs/web1-error_log #错误日志存放位置及名称
CustomLog logs/web1-access_log common #访问日志存放位置及名称common为设定的别名
</VirtualHost>
<VirtualHost 192.168.10.120:80>
ServerAdmin admin@web2.lg.com
DocumentRoot /www/docs/web2
<Directory "/www/docs/web2">
AllowOverride None
Options Indexes
Require all granted
</Directory>
ServerName web2.lg.com
ErrorLog logs/web2-error_log
CustomLog logs/web2-access_log common
</VirtualHost>