Apr 30

apache 大小階都能讀

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

在httpd.conf加入

#LoadModule speling_module modules/mod_speling.so 請先把最頭的# 移除

加入
CheckSpelling on

重新啟動apache 就可以了


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書




Jan 10

世界上還真多無聊人士,吃飽就想如何攻擊別人的網站, 一種常見的攻擊是貼廣告或是莫名其妙的留言,這些都是要廣告特定的 URL,這都是小問題,但另有一種刻意要癱瘓網站的攻擊,常見的作法就是發動很多很多的用戶端要求,持續讓網站窮於應付,用掉資源(CPU的資源, socket的資源,頻寬的資源…),而使得網站無法服務正常的使用者,這就是所謂的 DoS — Denial of Service 攻擊,稱為阻絕服務攻擊

針對 DoS 攻擊,官方的 Apache 本身並沒有提供解決之道,現在找到的是一個 3rd party 的模組,mod_evasive, 用以下原理防治: Detection is performed by creating an internal dynamic hash table of IP Addresses and URIs, and denying any single IP address from any of the following:

  • Requesting the same page more than a few times per second
  • Making more than n concurrent requests on the same child per second
  • Making any requests while temporarily blacklisted (on a blocking list)

它的 README 寫對付 DDoS — Distributed DoS 也有效

以下說明一下安裝及設定過程
下載地址:http://www.zdziarski.com/projects/mod_evasive/

$ wget http://www.zdziarski.com/projects/mod_evasive/mod_evasive_1.10.1.tar.gz
$ tar zxvf mod_evasive_1.10.1.tar.gz
$ cd mod_evasive
$ /usr/sbin/apxs -cia mod_evasive20.c
編譯完成後,/usr/lib/httpd/modules/ 下會生成一個 mod_evasive20.so 模組檔
安裝時會自動在 /etc/httpd/conf/httpd.conf 內加入以下內容:

LoadModule evasive20_module   /usr/lib/httpd/modules/mod_evasive20.so

以下為設定 mod_evasive20 模組,在 /etc/httpd/conf/httpd.conf 內加入以下內容:

#記錄和存放黑名單的哈西表大小,如果服務器訪問量很大,可以加大該值
DOSHashTableSize 3097
#同一個頁面在同一時間內可以被統一個用戶訪問的次數,超過該數字就會被列為攻擊,同一時間的數值可以在DosPageInterval參數中設置。
DOSPageCount 3
#同一個用戶在同一個網站內可以同時打開的訪問數,同一個時間的數值在DOSSiteInterval中設置。
DOSSiteCount 40
#設置DOSPageCount中時間長度標準,默認值為1。
DOSPageInterval 2
#DOSSiteInterval 2 設置DOSSiteCount中時間長度標準,默認值為1。
DOSSiteInterval 2
#被封時間間隔秒,這中間會收到 403 (Forbidden) 的返回。
DOSBlockingPeriod 10
#設置受到攻擊時接收攻擊信息提示的郵箱地址。
#DOSEmailNotify you@yourdomain.com
#受到攻擊時Apache運行用戶執行的系統命令
#DOSSystemCommand 「su - someuser -c 『/sbin/… %s …』」
#攻擊日誌存放目錄,BSD上默認是 /tmp
#DOSLogDir 「/var/lock/mod_evasive」
完成之後, restart httpd 即可

$ service httpd restart

可以利用 安裝目錄內的 test.pl 測試看看結果

HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden

恩,不錯有效果!


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書




Oct 10

Apache SSI 教程

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

本文參照的系統環境:

l Windows XP SP2

l Apache HTTP Server v2.0.55 (Win32)

什麼是 SSI

SSIServer Side Includes),是嵌套在 HTML 網頁中的指示語句,由後台服務器進行代碼的解釋計算。使用 SSI 可以動態的創建一部分網頁內容而不需要編寫複雜的 JSP/ASP/PHP 等程序。SSI 是如此的小巧以至於不應算作一門語言,因為他遠沒有JSP/ASP/PHP 等程序那麼複雜,只有一些極其有限的語法規則。但就算是只有這有限的一點語法規則,只要開動起你創新的思維,仍然可以「小才大用」,為你帶來效率的提高、體力的節省和腦力的放鬆 J

很多 HTTP Server 程序都支持 SSI,可能語法稍有不同,比如: IIS/Novell HTTP Server 等等,大同小異,本文要說明的是 Apache 2.0 SSI。閒話少說,我想告訴大家的是,這是一篇實踐經驗總結性的文章,後文中的示例解決方案都是來自實際的網站應用中。其中的一些想法和概念會給你帶來提示性的參考或者直接拿為所用。

下圖展示了 SSI 被服務器解釋,生成最終的純 HTML 網頁後,再發送給訪問者瀏覽的過程:

 

系統環境安裝

這不是一篇教你如何配置 Apache 的文章,但為了在你在本地系統環境測試的方便,還是簡單的說明一下。

首先可以到 http://www.apache.org/ 網站去下載一份最新的 Apache 安裝文件,安裝之後是否要做其他設置請自行參考相關資料,這裡只說明如何開啟 SSI 支持的步驟。

我在本地創建了一個 bnn 的文件夾,設成虛擬目錄,然後就可以通過瀏覽器訪問:http://localhost/bnn/

打開 Apache 的配置文件,例如:C:\Program Files\Apache Group\Apache2\conf\httpd.conf

然後加入類似下面的這段代碼(主要是中間的三行):黑體字部分是文件夾路徑。

<Directory “D:/Works/Jan-Boy/bnn“>

AddType text/html .ssi

Options Includes

AddOutputFilterByType INCLUDES;DEFLATE text/html

</Directory>

OK,「RestartApache Server (如果右下角系統欄中有 apache 小圖標,則左鍵點擊選擇 Restart 也可以在「開始 -> 程序」菜單的 Apache 項下面找到 Restart 命令; 還可以直接在安裝目錄運行C:\Program Files\Apache Group\Apache2\bin \ApacheMonitor.exe 後點擊 Restart 按鈕)。

測試 SSI 是否已經打開,在 bnn 文件夾下面新建一個 index.html 文件,打開後在裡面寫上:

<!–#echo var=”DATE_LOCAL” –>

保存關閉,然後打開瀏覽器測試:http://localhost/bnn/

如果正確的顯示出類似「Wednesday, 01-Mar-2006 02:03:06 China Standard Time」這樣的文字就表示 SSI 開啟成功!

「呼~~」深呼一口氣,搞掂,收工!
閱讀這篇文章的其餘部分 »


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書




Oct 10

Log Rotate for Apache

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Apache will lock the log file and syslog also cannot rotate it.
so we need a program cronolog
1. download most update version from http://cronolog.org/
2. unzip the file
3. ./configure
4. make
5. make install
6. configure the apache
CustomLog “|/usr/sbin/cronolog /var/www/logs/domain.com-access_log.%Y%m%d” common
ErrorLog “|/usr/sbin/cronolog /var/www/logs/domain.com-error_log.%Y%m%d”
7. restart apache
8. Done


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書




Oct 09

#DocumentRoot “C:/Program Files/Apache Group/Apache2/htdocs”
DocumentRoot “D:/vss” #修改root文件夾
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the “default” to be a very restrictive set of
# features.
#

閱讀這篇文章的其餘部分 »


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書




Oct 09

Apache 限制IP訪問

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

<Directory "/vhost dir/">
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Deny from all
Allow from 172.16.0.0/255.255.0.0

</Directory>


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書




Oct 09

apche 防止圖片盜鏈

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

######## Preventing Image ‘Theft’ ########

SetEnvIfNoCase Referer “^http://(.)+\.vincent\.idv\.hk/” local_ref=1
SetEnvIfNoCase Referer “-” local_ref=1
######## Allow the LOGO image Theft ##########
SetEnvIf Request_URI “/images/logo(.)+” local_ref=0

<FilesMatch “\.(png|gif|jpg)”>
Order Allow,Deny
Allow from env=local_ref
</FilesMatch>

參考文檔:

Preventing Image ‘Theft’ By: Ken Coar
Preventing hot linking of images by JavaScript Kit
SetEnvIfNoCase 和 SetEnvIf 的說明文檔
http://httpd.apache.org/docs-2.0/mod/mod_setenvif.html#setenvif


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書




Oct 09

限制並發數
下載模塊:

到官方網址: http://www.nowhere-land.org/programs/mod_vhost_limit/下載模塊

http://www.nowhere-land.org/programs/mod_vhost_limit/mod_vhost_limit-0.4.tar.gz

閱讀這篇文章的其餘部分 »


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書




Oct 09

Apache 限制IP連接數

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

限制IP連接數

到這裡下載模塊 http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz

安裝:
tar zxvf mod_limitipconn-0.04.tar.gz
cd mod_limitipconn-0.04
make APXS=/usr/local/apache/bin/apxs s—–這裡要按你自己的路徑設置
make install APXS=/usr/local/apache/bin/apxs s—–這裡要按你自己的路徑設置

編輯httpd.conf
添加
全局變量:
< IfModule mod_limitipconn.c >
< Location / > # 所有虛擬主機的/目錄
MaxConnPerIP 3 # 每IP只允許3個並發連接
NoIPLimit image/* # 對圖片不做IP限制
< /Location >

< Location /mp3 > # 所有主機的/mp3目錄
MaxConnPerIP 1 # 每IP只允許一個連接請求
OnlyIPLimit audio/mpeg video # 該限制只對視頻和音頻格式的文件
< /Location >
< /IfModule >

或者虛擬主機的:
< VirtualHost xx.xxx.xx.xx > ##ip 地址
ServerAdmin easy@phpv.net
DocumentRoot /home/easy
ServerName www.phpv.net
< IfModule mod_limitipconn.c >
< Location / >
MaxConnPerIP 5
NoIPLimit image/*
< /Location >
< Location /mp3 > # 所有主機的/mp3目錄
MaxConnPerIP 2 # 每IP只允許一個連接請求
OnlyIPLimit audio/mpeg video # 該限制只對視頻和音頻格式的文件
< /Location >
< /IfModule >
< /VirtualHost >


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書




Oct 09

Apache 限制頻寬

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

1、APACI 安裝
cp mod_bandwidth.c /path/to/apache/source./configure –add-module=mod_bandwidth.c –permute-module=BEGIN:bandwidth
2、DSO方式安裝
apxs -c /mod_bandwidth.c -o /path/to/apache/libexec/mod_bandwidth.so

閱讀這篇文章的其餘部分 »


Written by 傻仔仔

光波24書網(http://www.24reader.com/) - 免費電子書

  

光波24書網(http://www.24reader.com/) - 新到電子書

  

光波24書網(http://www.24reader.com/) - 快將推出電子書