利用Apache伺服器屏蔽廣告及IP段的一般方法_Linux

來源:互聯網
上載者:User

屏蔽廣告

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來訪問網站,
下面介紹一個簡單的屏蔽指定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訪問。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.