首页 > 开发 > Apache > 正文

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

2019-10-13 16:45:36
字体:
来源:转载
供稿:网友
这篇文章主要介绍了利用Apache服务器屏蔽广告及IP段的一般方法,同时也介绍了设置仅允许访问的IP段从而屏蔽其他一切IP的方法,需要的朋友可以参考下
 

屏蔽广告

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

例如:

#屏蔽百度视屏广告:127.0.0.1 a.baidu.com127.0.0.1 baidutv.baidu.com127.0.0.1 bar.baidu.com127.0.0.1 c.baidu.com127.0.0.1 cjhq.baidu.com127.0.0.1 cpro.baidu.com127.0.0.1 drmcmm.baidu.com127.0.0.1 e.baidu.com127.0.0.1 eiv.baidu.com127.0.0.1 hc.baidu.com127.0.0.1 hm.baidu.com127.0.0.1 ma.baidu.com127.0.0.1 nsclick.baidu.com127.0.0.1 spcode.baidu.com127.0.0.1 tk.baidu.com127.0.0.1 union.baidu.com127.0.0.1 ucstat.baidu.com127.0.0.1 utility.baidu.com127.0.0.1 utk.baidu.com127.0.0.1 focusbaiduafp.allyes.com

 

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

<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"# doesn't 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,denyAllow from all<IfModule mod_rewrite.c>RewriteEngine OnRewriteCond $1 !(adimage.html)$RewriteRule ^(.*)$ /adimage.html [L]</IfModule></Directory>

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

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

<html>  <body>    <!--<image src="/adimage/psb.jpg">-->    <?php echo "我卖广告我@#$%^&*,哦也!"; ?>  </body><html>

4.效果图

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

 

有些时候查看apache日志,会发现很多莫名其面的IP来访问网站,
下面介绍一个简单的屏蔽指定IP或者IP端的方法:
 
 
定位到你的Apache安装目录下的conf文件夹,
找到httdp.conf文件,
加入如下内容:
 

<Directory "你的网站根目录">  Options Indexes FollowSymLinks  AllowOverride None  Order deny,allow  Deny from 192.168.1.99   </Directory>

 
解释如下:
1、
<Directory  "你的网站根目录">,这里“你的网站根目录”是在这个httdp.conf文件里,
使用
DocumentRoot "你的网站根目录" 语句定义的 双引号 "……" 里的值,比如说/var/www/html之类的。
 
2、AllowOverride None
 
# AllowOverride 这个属性有两个值,None和All
当 AllowOverride 的值为All时,网站根目录里面的 .htaccess文件才能生效。
至于什么是.htaccess文件,请自己Google。
 
3、
   

Order deny,allow  Deny from 192.168.1.99 

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

# 允许所有主机访问  Order deny,allow  Allow from All 

 

# 禁止所有主机访问  Order deny,allow  Deny from All

 
把上面的All改成指定的IP即可达到屏蔽某个IP的效果。
屏蔽IP端也一样,比如说屏蔽192.168.1.123这个IP所在的192.168.1这个IP段,只需要这样写:

 # 禁止192.168.1这个IP段访问  Order deny,allow  Deny from 192.168.1.123/24

 
另注:
当书写为:

  Order deny,allow  Deny from All  Allow from 192.168.1.100

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

  Order deny,allow  Allow from All  Deny from 192.168.1.100

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



发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表