小知识:利用Apache服务器屏蔽广告及IP段的一般方法

屏蔽广告

1.在hosts文件里对需要屏蔽广告的网站加上host

例如:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#屏蔽百度视屏广告:
127.0.0.1 a.baidu.com
127.0.0.1 baidutv.baidu.com
127.0.0.1 bar.baidu.com
127.0.0.1 c.baidu.com
127.0.0.1 cjhq.baidu.com
127.0.0.1 cpro.baidu.com
127.0.0.1 drmcmm.baidu.com
127.0.0.1 e.baidu.com
127.0.0.1 eiv.baidu.com
127.0.0.1 hc.baidu.com
127.0.0.1 hm.baidu.com
127.0.0.1 ma.baidu.com
127.0.0.1 nsclick.baidu.com
127.0.0.1 spcode.baidu.com
127.0.0.1 tk.baidu.com
127.0.0.1 union.baidu.com
127.0.0.1 ucstat.baidu.com
127.0.0.1 utility.baidu.com
127.0.0.1 utk.baidu.com
127.0.0.1 focusbaiduafp.allyes.com

2. 设置apache转发,这里直接用默认路径改

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<Directory “E:/Apache Software Foundation/Apache2.2/htdocs”>
#
# Possible values for the Options directive are “None”, “All”,
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that “MultiViews” must be named *explicitly* — “Options All”
# doesnt give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !(adimage.html)$
RewriteRule ^(.*)$ /adimage.html [L]
</IfModule>
</Directory>

这里会将所有adimage.html的页面都转发到?adimage.html

3.配置一下转发到的页面

?
1
2
3
4
5
6
<html>
<body>
<!–<image src=”/adimage/psb.jpg”>–>
<?php echo “我卖广告我@#$%^&*,哦也!”; ?>
</body>
<html>

4.效果图

%小知识:利用Apache服务器屏蔽广告及IP段的一般方法-猿站网-插图

有些时候查看apache日志,会发现很多莫名其面的IP来访问网站,

下面介绍一个简单的屏蔽指定IP或者IP端的方法:

定位到你的Apache安装目录下的conf文件夹,

找到httdp.conf文件,

加入如下内容:

 
?
1
2
3
4
5
6
<Directory “你的网站根目录”>
Options Indexes FollowSymLinks
AllowOverride None
Order deny,allow
Deny from 192.168.1.99  
</Directory>

解释如下:

1、

,这里“你的网站根目录”是在这个httdp.conf文件里, >

使用

DocumentRoot “你的网站根目录” 语句定义的 双引号 “……” 里的值,比如说/var/www/html之类的。

2、AllowOverride None

# AllowOverride 这个属性有两个值,None和All

当 AllowOverride 的值为All时,网站根目录里面的 .htaccess文件才能生效。

至于什么是.htaccess文件,请自己Google。

3、

   
?
1
2
Order deny,allow
Deny from 192.168.1.99

使用这个命令来达到屏蔽IP的作用,类似的用法还有:

?
1
2
3
# 允许所有主机访问
Order deny,allow
Allow from All
?
1
2
3
# 禁止所有主机访问
Order deny,allow
Deny from All

把上面的All改成指定的IP即可达到屏蔽某个IP的效果。

屏蔽IP端也一样,比如说屏蔽192.168.1.123这个IP所在的192.168.1这个IP段,只需要这样写:
?
1
2
3
# 禁止192.168.1这个IP段访问
Order deny,allow
Deny from 192.168.1.123/24

另注:

当书写为:
?
1
2
3
Order deny,allow
Deny from All
Allow from 192.168.1.100

此时是禁止除了192.168.1.100这个IP之外的所有IP访问,也就是Deny,Allow这两个命令,在最后一个命令完成时才确定允许那些IP,禁止哪些IP。

请举一反三:
?
1
2
3
Order deny,allow
Allow from All
Deny from 192.168.1.100

没错,这段的意思是 允许除了192.168.1.100之外的所有IP访问。

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Kafka使用入门教程

2023-3-16 14:05:40

建站知识

小知识:高防CDN和高防IP是什么?有什么不同

2023-3-16 14:20:26

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索