发布于 2016-02-08 03:07:40 | 144 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Apache Web服务器

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件。


这篇文章主要介绍了利用Apache服务器屏蔽广告及IP段的一般方法,同时也介绍了设置仅允许访问的IP段从而屏蔽其他一切IP的方法,需要的朋友可以参考下

屏蔽广告

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

例如:


#屏蔽百度视屏广告:
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转发,这里直接用默认路径改


<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,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.配置一下转发到的页面


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

4.效果图

有些时候查看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访问。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务