[转帖]apache2.0.54防止盗连接详细配置

本文介绍如何通过Apache的mod_rewrite模块实现防盗链功能。包括编译安装Apache并启用mod_rewrite模块,配置httpd.conf文件,创建并使用.htaccess文件来限制外部链接访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要让apache防盗连接,首先要让apache支持.htaccess客户设置文件,还要增加mod_rewrite模块。以下是我的编译安装过程。 
1. 安装apache增加mod_rewrite模块 
tar xfzv httpd-2.0.54.tar.gz 
cd httpd-2.0.54 
./configure --prefix=/usr/local/httpd --enable-module=most --enable-shared=max --enable-rewrite 
--enable-rewrite将od_rewrite模块编译进来 
make 
make install 
查看apache编译进来的模块 
[root@TFP httpd-2.0.54]# /usr/local/httpd/bin/apachectl  -l 
Compiled in modules: 
 core.c 
 mod_access.c //支持.htaccess文件 
 mod_auth.c 
 mod_include.c 
 mod_log_config.c 
 mod_env.c 
 mod_setenvif.c 
 prefork.c 
 http_core.c 
 mod_mime.c 
 mod_status.c 
 mod_autoindex.c 
 mod_asis.c 
 mod_cgi.c 
 mod_negotiation.c 
 mod_dir.c 
 mod_imap.c 
 mod_actions.c 
 mod_userdir.c 
 mod_alias.c 
 mod_rewrite.c //已经将od_rewrite编译进来了 
 mod_so.c 
[root@TFP httpd-2.0.54]# 
2.设置apache配置文件httpd.conf 
<Directory /> 
   Options FollowSymLinks 
   AllowOverride All   将None修改为All 
</Directory> 


AllowOverride All   将None修改为All 
修改默认APACHE名去掉#ServerName前的#设置为127.0.0.1 
ServerName 127.0.0.1 
设置虚拟主机 

NameVirtualHost 220.202.19.82 
<VirtualHost 220.202.19.82> 
   DocumentRoot /home/down 
   ServerName down.sy165.cn 
</VirtualHost> 

重启Apache2服务器 
接下就是做一个 .htaccess 文件了,其 .htaccess 文件内容为 
RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://www.sy165.cn/.*$  [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.sy165.cn$  [NC] 
RewriteRule .*/.(jpg|jpeg|gif|png|bmp|rar|zip|exe)$ http://www.sy165.cn/err.htm [R,NC] 

将这个文件放到/home/down目录下 
RewriteCond %{HTTP_REFERER} !^http://www.sy165.cn/.*$  [NC] 
只允许通过www.sy165.cn/*才能下载down.sy165.cn下的文件。 
RewriteCond %{HTTP_REFERER} !^http://www.sy165.cn$  [NC] 
只允许通过www.sy165.cn才能下载down.sy165.cn下的文件 
RewriteRule .*/.(jpg|jpeg|gif|png|bmp|rar|zip|exe)$ http://www.sy165.cn/err.htm [R,NC] 
jpg|jpeg|gif|png|bmp|rar|zip|exe是要保护的内容,如果岛连接将跳转到http://www.sy165.cn/err.htm 

测试地址可以通过http://www.sy165.cn下载CS1.6 标准版3147版下载 
不能直接通过URL:http://down.sy165.cn/game/CS_16_3174.exe 下载
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值