利用Apache服務(wù)器屏蔽廣告及IP段的一般方法
屏蔽廣告
1.在hosts文件里對需要屏蔽廣告的網(wǎng)站加上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 # 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. 設(shè)置apache轉(zhuǎn)發(fā),這里直接用默認(rèn)路徑改
<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的頁面都轉(zhuǎn)發(fā)到?adimage.html
3.配置一下轉(zhuǎn)發(fā)到的頁面
<html> <body> <!--<image src="/adimage/psb.jpg">--> <?php echo "我賣廣告我@#$%^&*,哦也!"; ?> </body> <html>
4.效果圖
有些時候查看apache日志,會發(fā)現(xiàn)很多莫名其面的IP來訪問網(wǎng)站,
下面介紹一個簡單的屏蔽指定IP或者IP端的方法:
定位到你的Apache安裝目錄下的conf文件夾,
找到httdp.conf文件,
加入如下內(nèi)容:
<Directory "你的網(wǎng)站根目錄"> Options Indexes FollowSymLinks AllowOverride None Order deny,allow Deny from 192.168.1.99 </Directory>
解釋如下:
1、
<Directory "你的網(wǎng)站根目錄">,這里“你的網(wǎng)站根目錄”是在這個httdp.conf文件里,
使用
DocumentRoot "你的網(wǎng)站根目錄" 語句定義的 雙引號 "……" 里的值,比如說/var/www/html之類的。
2、AllowOverride None
# AllowOverride 這個屬性有兩個值,None和All
當(dāng) AllowOverride 的值為All時,網(wǎng)站根目錄里面的 .htaccess文件才能生效。
至于什么是.htaccess文件,請自己Google。
3、
Order deny,allow Deny from 192.168.1.99
使用這個命令來達(dá)到屏蔽IP的作用,類似的用法還有:
# 允許所有主機(jī)訪問 Order deny,allow Allow from All
# 禁止所有主機(jī)訪問 Order deny,allow Deny from All
把上面的All改成指定的IP即可達(dá)到屏蔽某個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
另注:
當(dāng)書寫為:
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訪問。
相關(guān)文章
xampp Apache啟動后無法訪問站點(diǎn)解決方法匯總
本文給大家總結(jié)了3種xampp Apache啟動后無法訪問站點(diǎn)解決方法,均能夠解決此問題,有需要的小伙伴可以參考下2015-03-03ubuntu+php環(huán)境下的Memcached 安裝方法
Memcached是一套分散式的高速緩存系統(tǒng),當(dāng)初是Danga Interactive為了LiveJournal所發(fā)展2011-11-11Windows下 Apache PHP 環(huán)境搭建的方法
經(jīng)常在 Linux 環(huán)境下搭建 php 環(huán)境,在 windows 下還是第一次,沒啥技術(shù)含量,就是記錄一下,需要的朋友參考下本教程2017-01-01詳解CentOS升級Python2.6到Python2.7并安裝pip
本篇文章主要介紹了CentOS升級Python2.6到Python2.7并安裝pip,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-03-03在 Linux 命令行中使用 tcpdump 抓包的一些功能
tcpdump 是一款靈活、功能強(qiáng)大的抓包工具,能有效地幫助排查網(wǎng)絡(luò)故障問題。接下來通過本文給大家介紹在 Linux 命令行中使用 tcpdump 抓包的一些常用功能,需要的朋友參考下吧2018-11-11