服务器 
首页 > 服务器 > 浏览文章

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

(编辑:jimmy 日期: 2024/9/21 浏览:3 次 )

屏蔽广告

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="/UploadFiles/2021-04-10/psb.jpg">

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访问。

上一篇:详解Tomcat服务器绑定多域名和虚拟目录的方法
下一篇:Windows系统下安装Tomcat服务器和配置虚拟目录的方法
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap