夕口技術錄

專業上的小常識,備而用之~

Category Archives: Apache

[Apache] – 設定伺服器所能接受之最大連續請求量

為了要防止不法人士,
使用某方式對網站在極短時間內,
進行大量的存取動作,
因此針對 http.conf 進行參數上的調。

TimeOut
語法:TimeOut <數字>
預設:TimeOut 300

TimeOut 用來設定伺服器接收一個請求以及完成一個請求最長的等待時間〈以秒為單位〉,如果在此時間內沒有回應則終止服務。所以當接收或傳送一個資料時所花的時間超過 TimeOut 所規定的時間時,伺服器便將會中斷該連線。如果網路速度較慢,則此 Timeout 時間可以設長一些。

例:TimeOut 500
-> 指定 apache 接收或傳送的等待時間

KeepAlive
語法:KeepAlive <(On/Off)>
預設:KeepAlive On

KeepAlive 用於設定伺服器要不要開啟連續請求的功能,On 是開啟,Off 是關閉。

例:KeepAlive On
-> 指定 apache 開啟連續請求功能

MaxKeepAliveRequests
語法:MaxKeepAliveRequests <個數>
預設:MaxKeepAliveRequests 100

MaxKeepAliveRequests 用於設定伺服器所能接受之最大連續請求量,如果連續請求超過這個此數限制則 Server 會自動拒絕請求連線。若設定為 0 則表示不做限制。

例:MaxKeepAliveRequests 0
-> 指定 apache 不限制所能接收之連線數量

KeepAliveTimeout
語法:KeepAliveTimeout <秒數>
預設:KeepAliveTimeout 15

KeepAliveTimeout 用於設定使用者 ‘連續’ 請求等待的時間上限,如果使用者連續請求的時間超過此數,則終止此請求服務。

例:KeepAliveTimeou 15
-> 指定 apache 等待使用者連續請求的時間,在接到使用者請求開始,15 秒內若沒收到新請求訊息,即中斷該連線

[Apache] – 設定伺服器所能接受之最大連續請求量

為了要防止不法人士,
使用某方式對網站在極短時間內,
進行大量的存取動作,
因此針對 http.conf 進行參數上的調。

TimeOut
語法:TimeOut <數字>
預設:TimeOut 300

TimeOut 用來設定伺服器接收一個請求以及完成一個請求最長的等待時間〈以秒為單位〉,如果在此時間內沒有回應則終止服務。所以當接收或傳送一個資料時所花的時間超過 TimeOut 所規定的時間時,伺服器便將會中斷該連線。如果網路速度較慢,則此 Timeout 時間可以設長一些。

例:TimeOut 500
-> 指定 apache 接收或傳送的等待時間

KeepAlive
語法:KeepAlive <(On/Off)>
預設:KeepAlive On

KeepAlive 用於設定伺服器要不要開啟連續請求的功能,On 是開啟,Off 是關閉。

例:KeepAlive On
-> 指定 apache 開啟連續請求功能

MaxKeepAliveRequests
語法:MaxKeepAliveRequests <個數>
預設:MaxKeepAliveRequests 100

MaxKeepAliveRequests 用於設定伺服器所能接受之最大連續請求量,如果連續請求超過這個此數限制則 Server 會自動拒絕請求連線。若設定為 0 則表示不做限制。

例:MaxKeepAliveRequests 0
-> 指定 apache 不限制所能接收之連線數量

KeepAliveTimeout
語法:KeepAliveTimeout <秒數>
預設:KeepAliveTimeout 15

KeepAliveTimeout 用於設定使用者 ‘連續’ 請求等待的時間上限,如果使用者連續請求的時間超過此數,則終止此請求服務。

例:KeepAliveTimeou 15
-> 指定 apache 等待使用者連續請求的時間,在接到使用者請求開始,15 秒內若沒收到新請求訊息,即中斷該連線

[Apache] – (98)Address already in use: make_sock: could not bind to address [::]:80?

問:

在進行 apache 重啟時發現以下問題出現 ?

# ./apachectl start
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

解:

使用 lsof 時才發現,
原來是網頁上執行程式中,
有人把它 lock 住了
# ps aux | grep snort
500      17211  0.0  0.2 53796 1124 ?        S    16:01   0:00 sh -c cd ‘/usr/local/apache/www/html’ ; /usr/bin/sudo /usr/local/apache/bin/snortc -l /usr/local/apache/log 1,2\> /dev/null \& <- 就是這行
root     17212  0.0  0.2 10092 1000 ?        S    16:01   0:00 /usr/local/apache/bin/snortc -l /usr/local/apache/log 1,2> /dev/null &
root     17669  0.0  0.1 51056  596 pts/1    R+   16:04   0:00 grep snort

因此把它 pid 直接 kill 掉就行啦 !!!

# lsof -i :80
COMMAND  PID      USER   FD   TYPE DEVICE SIZE NODE NAME
sh       713   apache    3u  IPv6 189115       TCP *:http (LISTEN)
sh      1795  apache    3u  IPv6 189115       TCP *:http (LISTEN)

# kill -9 713 1795
# ./apachectl start
# pgrep httpd
3774
3776
3777
3779
3780
3781
3782
3790
3792
3794
3795
3796

[Apache][shell] – Apache 每天自動重啟程式


/usr/local/server/bin/shell_process_restart
#!/usr/local/server/bin/php -q

<?php

$ns_path = "/usr/local/server/";

//SIKO-> step.1 stop
$apache_process_stop = escapeshellcmd($ns_path."bin/apachectl stop");
$apache_process_test = escapeshellcmd("pgrep httpd");
do{
exec($apache_process_stop);
system($apache_process_test,$ptset);
$i++;
}
while($ptset == 0 && $i < 10000);

//SIKO-> step.2 start
$apache_process_start = escapeshellcmd($ns_path."bin/apachectl start");
do{
exec($apache_process_start);
system($apache_process_test,$ptset);
$j++;
}
while($ptset == 1 && $j < 10000);

?>

[crontab]
00 01 * * * /usr/local/server/bin/lockrun --lockfile=/usr/local/server/log/shell_process_restart.lock -- /usr/local/server/bin/shell_process_restart > /dev/null 2>&1

[Apache] -防制 惡意攻擊的加強安全性mod_security模組

目前網路有現成的模組 您可以使用 mod_security 增加 Apache 的安全性
mod_security 是 Apache 的一個模組
可以提供入侵偵測及防禦,它就如同是web應用程式的防火牆
可以用來抵擋知名及不知名的攻擊如 SQL injection attacks 、cross-site scripting、path traversal attacks
以下說明安裝過程:

mod_security 1.9.x模塊的下載與安裝

下載地址:http://www.modsecurity.org/download/index.html

建議使用1.9.x,因為2.x的配置指令與1.x完全不同

以下說明一下安裝及設定過程:

$ wget http://www.modsecurity.org/download/modsecurity-apache_1.9.5.tar.gz
$ tar zxvf modsecurity-apache_1.9.5.tar.gz
$ cd modsecurity-apache_1.9.5
$ cd apache2
$ /usr/sbin/apxs -cia mod_security.c

編譯完成後,/usr/lib/httpd/modules/ 下會生成一個 mod_security.so 模組檔
安裝時會自動在 /etc/httpd/conf/httpd.conf 內加入以下內容:

LoadModule security_module /usr/lib/httpd/modules/ mod_security.so

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

<IfModule mod_security>
# 打開過濾引擎開關。如果是Off,那麼下面這些都不起作用了。
SecFilterEngine On
# 把設置傳遞給字目錄
SecFilterInheritance Off
# 檢查url編碼
SecFilterCheckURLEncoding On
# 檢測內容長度以避免堆溢出攻擊
#SecFilterForceByteRange 32 126
# 日誌的文件和位置。一定要先建立好目錄,否則apache重新啟動的時候會報錯。
SecAuditLog /var/log/httpd/mod_security_audit_log
# debug的設置
SecFilterDebugLog /var/log/httpd/mod_security_debug_log
SecFilterDebugLevel 9
#當匹配chmod,wget等命令的時候,重新定向到一個特殊的頁面,讓攻擊者知難而退
SecFilter chmod redirect:http://www.google.com
SecFilter wget redirect:http://www.google.com
# 預設的動作
SecFilterDefaultAction “deny,log,status:406″
# 防止操作系統關鍵詞攻擊
SecFilter /etc/*passwd
SecFilter /bin/*sh
# 防止double dot攻擊
SecFilter “\.\./"
# 防止跨站腳本(CSS)攻擊
SecFilter “<( |\n)*script"
# Prevent XSS atacks (HTML/Javascript injection)
SecFilter “<(.|\n)+>"
# 防止sql注入式攻擊
SecFilter “delete[[:space:]]+from"
SecFilter “insert[[:space:]]+into"
SecFilter “select.+from"
#偽裝服務器標識
SecServerSignature “Microsoft-IIS/6.0″
</IfModule>

完成之後, restart httpd 即可

$ service httpd restart

這樣就大功告成喔!這麼一來系統的安全性就又提升了唷!
我想建議大家多多使用這個模組,不要說盜連,其實很多入侵行為都是藉由網頁而植入惡意程式的,修補及更新當然是需要的,但是如果能藉由一些現成的套件來對自己的網站多一些防護的話,我想安全性還是可以提高一些。

官方首頁

簡介

專家寫好的規則

[Apache][PHP] – 為 HTTP URL隱藏 .php 副檔名

為了簡化網址或是為了安全理由, 會希望將副檔名隱藏. 也就是說原本
http://www.xxx.yyy/test.php
只需要
http://www.xxx.yyy/test
就可以連上, 這樣可以讓網站所有連結都不出現副檔名
這就像yahoo的新服務 知識+ 一樣裡頭的連結完全沒出現.php
但經過我測試不管連到
http://tw.knowledge.yahoo.com/index
http://tw.knowledge.yahoo.com/index.php
其實是一樣的, 也就是說這個系統其實是php開發的
只是為了不要暴露使用的程式語言而隱藏了
另外yahoo還有一招, 就是任何的錯誤訊息都是自訂的錯誤訊息, 則是可以隱藏使用的伺服器型態.
下面講一下我找到的設定方法
1.
到apache的http.conf找到下面這行
#LoadModule rewrite_module modules/mod_rewrite.so
這一行註解拿掉
LoadModule rewrite_module modules/mod_rewrite.so
於是rewrite_mod模組啟動了! (他的功用請參考官方資訊)
2.
在 http.conf加入

AllowOverride all #這行的意思是說, 允許 .htaccess 檔的內容覆蓋這邊的設定
Order allow,deny
Allow from all

3.
新增一個 .htaccess檔在剛剛的目錄底下, 在裡頭寫入

Options +FollowSymlinks
#下行是設定要不要啟用rewrite engine, 這是runtime的設定檔,不需restartserver
RewriteEngine on
#下行是將檔名中沒有slash 和 . 的檔名, 轉向到 .php的檔案
RewriteRule ^([^./]+)/?$ $1.php [L]

4. 剛剛已經針對某個目錄做設定, 之後若底下的子目錄也要有同樣功能 ,請再將 .htaccess檔直接複製到要套用的子目錄即可

[Apache2] – 頻寬限制模組 mod cband

如果你是用Apache Web Server自己架站,
而且對外頻寬又不大的話,
是否常因為對外頻寬被你架設的網站使用完,
而造成你整各網路都很慢呢?

伺服器安裝上了 mod_cband MODULE,這個MODULE相當好用,
可以用來解決架設 Apache 頻寬問題,
它可以讓 Apache 來控制管理你的頻寬,
才不會導致對外(Up Bandwith)頻寬被用完,
連帶影響對內(Down Bandwith)頻寬也變慢。

以下說明我的安裝過程:
我的安裝環境:
CentOS 5.0
Apache 2.2.3

先去下載該模組: mod_cband 目前釋出到 0.9.7.5 版 http://cband.linux.pl/

下載到 /tmp/ 資料夾裡面
# cd /tmp
# wget http://cband.linux.pl/download/mod-cband-0.9.7.5.tgz

解壓縮: tar -zxvf mod-cband-0.9.7.5.tgz

如果你有安裝 apsx 或 apsx2 的話 請用下面安裝 (我用此方式,因我有安裝 apsx )
# cd mod-cband-0.9.7.5
# ./configure
checking for gcc… gcc
checking for C compiler default output file name… a.out
checking whether the C compiler works… yes
checking whether we are cross compiling… no
checking for suffix of executables…
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ANSI C… none needed
checking whether make sets $(MAKE)… yes
checking for apr_palloc in -laprutil… no
checking for an ANSI C-conforming const… yes
checking for apxs… apxs
checking how to run the C preprocessor… gcc -E
checking for egrep… grep -E
checking for ANSI C header files… yes
checking for sys/types.h… yes
checking for sys/stat.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for stdint.h… yes
checking for unistd.h… yes
checking stdio.h usability… yes
checking stdio.h presence… yes
checking for stdio.h… yes
checking for string.h… (cached) yes
checking assert.h usability… yes
checking assert.h presence… yes
checking for assert.h… yes
checking ctype.h usability… yes
checking ctype.h presence… yes
checking for ctype.h… yes
checking errno.h usability… yes
checking errno.h presence… yes
checking for errno.h… yes
checking math.h usability… yes
checking math.h presence… yes
checking for math.h… yes
checking netinet/in.h usability… yes
checking netinet/in.h presence… yes
checking for netinet/in.h… yes
checking sys/socket.h usability… yes
checking sys/socket.h presence… yes
checking for sys/socket.h… yes
checking arpa/inet.h usability… yes
checking arpa/inet.h presence… yes
checking for arpa/inet.h… yes
configure: creating ./config.status
config.status: creating Makefile

# make
apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -c src/mod_cband.c
/usr/lib64/apr-1/build/libtool –silent –mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -Wall -DDST_CLASS=3  -c -o src/mod_cband.lo src/mod_cband.c && touch src/mod_cband.slo
src/mod_cband.c:81: warning: type qualifiers ignored on function return type
/usr/lib64/apr-1/build/libtool –silent –mode=link gcc -o src/mod_cband.la  -rpath /usr/lib64/httpd/modules -module -avoid-version    src/mod_cband.lo

# make install
apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -i -a -n cband src/mod_cband.la
/usr/lib64/httpd/build/instdso.sh SH_LIBTOOL=’/usr/lib64/apr-1/build/libtool’ src/mod_cband.la /usr/lib64/httpd/modules
/usr/lib64/apr-1/build/libtool –mode=install cp src/mod_cband.la /usr/lib64/httpd/modules/
cp src/.libs/mod_cband.so /usr/lib64/httpd/modules/mod_cband.so
cp src/.libs/mod_cband.lai /usr/lib64/httpd/modules/mod_cband.la
cp src/.libs/mod_cband.a /usr/lib64/httpd/modules/mod_cband.a
chmod 644 /usr/lib64/httpd/modules/mod_cband.a
ranlib /usr/lib64/httpd/modules/mod_cband.a
PATH="$PATH:/sbin" ldconfig -n /usr/lib64/httpd/modules
———————————————————————-
Libraries have been installed in:
/usr/lib64/httpd/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR’
flag during linking and do at least one of the following:
– add LIBDIR to the `LD_LIBRARY_PATH’ environment variable
during execution
– add LIBDIR to the `LD_RUN_PATH’ environment variable
during linking
– use the `-Wl,–rpath -Wl,LIBDIR’ linker flag
– have your system administrator add LIBDIR to `/etc/ld.so.conf’

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
———————————————————————-
chmod 755 /usr/lib64/httpd/modules/mod_cband.so
[activating module `cband’ in /etc/httpd/conf/httpd.conf]

安裝一切順利沒有錯誤訊息,安裝過程中編譯好 mod_cband.so 且被放置到 Apache 的模組資料夾(/usr/lib64/httpd/modules/)內了
及在 Apache 的設定檔(/etc/httpd/conf/httpd.conf)內加入了載入模組
LoadModule cband_module       /usr/lib64/httpd/modules/mod_cband.so


至此mod_cband裝設已經完成,所以後續再設定要管控的相關設定即可!

如果沒有安裝 apsx 或 apsx2 的話 請用下面的方式編譯
# cd mod-cband-0.9.7.5
# ./configure –add-module=../mod-cband/mod_cband.c –enable-shared=cband –enable-module=so
# make
# make install

使用該模組對 VirtualHost 設定可以使用的頻寬 (在 mos-cband 模組解壓縮後有一個 INSTALL 檔,裡面有詳述)
以下我針對我的設定說明:

設定 /etc/httpd/conf/httpd.conf
以下使用最簡單的方式配置,不作假為複雜的配置,如:CBandClass

<VirtualHost xxx.xxx.xxx.xxx>  # 此處 xxx.xxx.xxx.xxx 請改成你的伺服器 對外 IP 位置
ServerName
www.xspace.idv.tw
ServerAdmin webmaster@xspace.idv.tw
DocumentRoot /var/www/www.xspace.idv.tw

#限制此虛擬主機最高訪問速度 1024kbps、每秒最高接受請求數 200 個 、最高並發連接 200 個
CBandSpeed 1024 200 200

#限制來自遠端訪問速度512kB每秒,30個請求每秒,30個連接。
CBandRemoteSpeed 512kb/s 30 30

#設定多久對所記錄的全域訪問頻寬進行重設(歸零)  4W=4 weeks 4 週 (一個月)
CBandPeriod 4W

#開啟 mod_cband 的即時監看功能,可以透過 http://server_name/cband-status 進行觀查。(全域監看)
SetHandler cband-status

#開啟 mod_cband 的即時監看功能,可以透過 http://server_name/cband-status-me 進行觀查。(單一監看)
SetHandler cband-status-me

</VirtualHost>

以上設定好後 重啟 Apache 服務 後連上這一個所設定的 VirtualHost 就會受到頻寬限制了
可參考官方的文件也壓縮安模組內的 INSTALL 或 doc 資料夾內的 documentation.txt  或 faq.txt 檔案
或可以使用 VirtualHost Template Configurator for Apache2 工具進行配置,但須 XWindows
VirtualHost Template Configurator for Apache2  官方網站:http://www.jackal-net.at/tiki-read_article.php?articleId=25

[Apache] – 防止盜連的方法

方法: 在 .htaccess 或 httpd.conf 中, 輸入以下敘述:

SetEnvIfNoCase Referer “^http://your.domain.name.tw/" ref=1
SetEnvIfNoCase Referer “^http://202.43.196.230/" ref=1

<FilesMatch “.(jpg|gif|png|wma|mrm)$">

Order allow,deny
Allow from env=ref
Allow from 127.0.0.1

</FilesMatch>

其中, 第二行的 http://202.43.196.230/ 是為了讓 Yahoo! 奇摩的『庫存網頁』能順利參照到限制的檔案, 如果您想開放更多的搜尋引擎庫存網頁可以參照進來, 請從 Log 檔中找出相關位址, 依此類推.


【教學】避免網站內容被人盜連
註:以下說明對於WIN+IIS架站的人,是無效的,不要一直問我為什麼無效…@@

以下是以UNIX(FREEBSD..LINUX等)+APACHE架站的人適用
只要設定1次,就不需再去設別的資料,
你也不需要1個1個去擋盜連來源的IP,這樣開站豈不是太累人了???
一天到晚要去檢查LOG…@@

首先在你的網站根目錄下開個.htaccess這個檔案,裡面寫下面資料:
以下是用PCZONE當例子,請換成你自己的網址
(如果你不是實體主機,沒有自己的固定IP,下面第3列的IP資料就不用去設定ㄛ)

SetEnvIfNoCase Referer “^http://www.pczone.com.tw/" local_ref=1
SetEnvIfNoCase Referer “^http://pczone.com.tw/" local_ref=1
SetEnvIfNoCase Referer “^http://202.43.85.163/" local_ref=1
<FilesMatch “.(txt|doc|gif|jpg|mp3)"> <–這邊隨你喜好自己設
Order Allow,Deny
Allow from env=local_ref
Allow from 127.0.0.1
</FilesMatch>

當你這樣寫好後,把檔案擺到網站的根目錄就OK
你網站上的檔案(凡是上面有設定到的,像TXT、DOC…)只能從站內被取用,
如果有人的來源是其它網站,因為來源IP不是你所允許的127.0.0.1主機內部,
因此在你主機空間被你設定的檔案、圖片、MP3就不會被人順利盜連了….

只要是經過你按上面步驟指名要求到的檔案
不管是GIF圖檔、影音檔、壓縮檔、程式..還是其他有的沒的..
只要你在.htaccess有設定到
全部、統統都有防止盜連的效果
這樣你的主機頻寬就不會被人給佔光或搞到流量破表被主機公司追債

只要你設定過,訪客就無法直接盜連(除非用軟體抓網站,但這應該是叫做"下載"網站檔案..)
.htaccess這9個字已經是完整的檔名,他沒有副檔名,千萬不要自己亂加副檔名,
開頭的.號代表是隱藏檔的意思!

經站友新的回報:WIN+APACHE可以使用上面的方法防止盜連

—————————————————————–

3月30日再補充以下教學:

有人問說,如果要開放某些站台可以直接連結自己網站內的資料,該怎麼辦?

例如你想開放pczone.com.tw站上的貼圖,可以直接從自己的網站被連結使用,
那麼請在.htaccess檔案加入下面這新的3行字:

(以下這樣設定代表:除了自己網站以及PCZONE網站,其他網站仍無法盜連你站內的資料)

SetEnvIfNoCase Referer “^http://www.pczone.com.tw/" local_ref=1
SetEnvIfNoCase Referer “^http://pczone.com.tw/" local_ref=1
SetEnvIfNoCase Referer “^http://自己網站的舊資料/" local_ref=
<FilesMatch “.(txt|doc|gif|jpg|mp3)">
Order Allow,Deny
Allow from env=local_ref
Allow from 127.0.0.1
Allow from 202.43.85.163 <-這個IP,是PCZONE網站的固定IP,一定要打進去!
</FilesMatch>


記錄盜用請求

如 果想知道自己網站的藝術品是否被盜,可以嘗試使用同樣的偵測和環境變數來記錄可疑請求。例如,在httpd.conf檔中添加如下命令,那麼會在/usr /local/web/apache/logs/poachers_log檔中記錄所有具有非法的Referer頭資訊的訪問請求:

代碼:
SetEnvIfNoCase Referer      “!^http://my.apache.org/" not_local_ref=1
SetEnvIfNoCase Request_URI  “.(gif|jpg)"               is_image=1
RewriteEngine  On
RewriteCond    ${ENV:not_local_ref} =1
RewriteCond    ${ENV:is_image}      =1
RewriteRule    .*                   –     [Last,Env=poach_attempt:1]
CustomLog logs/poachers_log         CLF   env=poach_attempt

在上面代碼中,頭兩行為條件設置標記(也就是沒有正確的本地Referer的圖片檔),RewriteCond檢測是否該標記被設置,然後RewriteRule設置第三個標記,最後一行使得這樣的訪問請求被記錄在特定的檔中。


重點:httpd.conf  內站台目錄的 AllowOverride 必須為 AllowOverride ALL 這樣, .htaccess  才能夠起作用


  1. Options
    表示這個目錄內能夠進行的動作,亦即是權限設定啦!主要的設定值:
  2. Indexes
    如果在此目錄下找不到『首頁檔案』時, 就顯示整個目錄下的檔案名稱,『首頁檔案』與 DirectoryIndex 設定值有關。
  • FollowSymLinks
    讓 在此目錄下的連結檔可以連結出此目錄外。 一般來說被 chroot 的程式將無法離開其目錄,也就是說預設的情況下,你在 /var/www/html 底下的連結檔只要連結到非此目錄的其他地方,則該連結檔預設是失效的。 但使用此設定即可讓連結檔有效的離開本目錄。
  • ExecCGI
    讓此目錄具有執行 CGI 程式的權限,非常重要!舉例來說,目前常見的 OpenWebMail 使用了很多的 perl 的程式, 你要讓 openwebmail 可以執行,就得要在 openwebmail 程式所在目錄 擁有 ExecCGI 的權限。注意,不要讓所有目錄均可使用 ExecCGI
  • Includes
    讓一些 Server-Side Include 程式可以運作。建議可以加上去!
  • MultiViews
    這 玩意兒有點像是多國語言的支持,與語系資料 (LanguagePriority) 有關。最常見在錯誤訊息的回報內容,在同一部主機當中, 可以依據用戶端的語系而給予不同的語言顯示呢!預設在錯誤回報訊息當中存在, 你可以檢查一下 /var/www/error/ 目錄下的資料喔!
  1. AllowOverride
    表 示是否允許額外設定檔 .htaccess 的權限複寫?我們可以在 httpd.conf 內設定好所有的權限,不過如此一來若使用者自己的個人網頁想要修改權限時將會對管理員造成困擾。因此 Apache 預設可以讓使用者以目錄底下的 .htaccess 檔案內複寫 <Directory> 內的權限設定。 這個項目則是在規定 .htaccess 可以複寫的權限類型有哪些。常見的有:
  2. ALL:全部的權限均可被複寫;
  • AuthConfig:僅有網頁認證 (帳號密碼) 可複寫;
  • Indexes:僅允許 Indexes 方面的複寫;
  • Limits:允許使用者利用 Allow, Deny 與 Order 管理可瀏覽的權限;
  • None:不可複寫,亦即 .htaccess 檔案失效去!
  1. Order
    決定是否可被瀏覽的權限設定啦!主要有兩種方式:
  2. deny,allow:以 deny 優先處理,但沒有寫入規則的則預設為 allow 喔。
  • allow,deny:以 allow 為優先處理,但沒有寫入規則的則預設為 deny 喔。
  1. 所以在預設的環境中,因為是 allow,deny 所以預設為 deny (不可瀏覽), 不過在下一行有個 Allow from all ,allow 優先處理,因此全部(all) 用戶端皆可瀏覽啦!這部份我們會在進階安全設定當中再提及低。

[Apache] – 檔案上傳限制設定

通常上傳檔案會出問題,
都是去修改 php.ini 中的 memory_limit, max_execution_time, post_max_size. 這些參數,
今天才發現到原來 Apache 也會去設定上傳檔案大小,
(應該是 Redhat 預設 Apache 有做修改).

只要在 httpd.conf 中加入如下.

<Files *.php>            SetOutputFilter PHP            SetInputFilter PHP            LimitRequestBody 524288 </Files>

將 LimitRequestBody 設為 2000000(2M),
就可以解決掉上傳只能上傳 500kb 的問題.

[Apache][mod_limitipconn] – 限制 Apache 的連線數

如果您的網站是很受人歡迎的網站,
可能會遭受到來自網路上一大堆惡意的多次連線,
造成網路的阻塞,
這時您可以安裝 mod_limitipconn 來解決這個問題。
mod_limitipconn 官方網站:http://dominia.org/djao/limitipconn.html
如果您用的 Apache Web Server 是 2.x 版,則要到下面網址下載:
http://dominia.org/djao/limitipconn2.html
底下是在 CentOS 4.4 環境下實作
rpm -Uvh mod_limitipconn-0.22-1.i386.rpm
看一下套件安裝到哪些路徑
rpm -qpl mod_limitipconn-0.22-1.i386.rpm
/etc/httpd/conf.d/limitipconn.conf
/usr/lib/httpd/modules/mod_limitipconn.so
/usr/share/doc/mod_limitipconn-0.22
/usr/share/doc/mod_limitipconn-0.22/ChangeLog
/usr/share/doc/mod_limitipconn-0.22/README


mod_limitipconn 主要設定檔在 /etc/httpd/conf.d 目錄之下的 limitipconn.conf
修改設定檔
vim /etc/httpd/conf.d/limitipconn.conf
<Location /test>
MaxConnPerIP 3
# exempting images from the connection limit is often a good
# idea if your web page has lots of inline images, since these
# pages often generate a flurry of concurrent image requests
NoIPLimit image/*
</Location>

/test 目錄,每個 IP 最多 3 個連線
image/* 目錄下圖片不受此限制