Archive for the ‘Apache’ Category

Apache + Python @ FreeBSD

星期日, 九月 6th, 2009

要讓 Apache 支援 Python,可以安裝 mod_python。
在 ports 裡有兩個版本,一個是 mod_python 2.7、一個是 mod_python 3.3,這兩種分別適用於不同版本的 Apache:

mod_python 2.7
  • Python 1.5.2, 1.6, 2.0 or 2.1
  • Apache 1.3
  • ports 路徑: /usr/ports/www/mod_python/
mod_python 3.3
  • Python 2.3.4 or later.
  • Apache 2.0.54 or later.
  • ports 路徑: /usr/ports/www/mod_python3/

挑選適合的 mod_python 版本後,到 ports 目錄下執行 make install clean 完成安裝。
安裝後會出現設定的說明:

Also remember to add to your Apache configuration in the appropriate context:
 
PythonPath "['/path/to/foo', '/path/to/bar']"
AddHandler python-program .py
PythonHandler foobar
PythonDebug On
 
For more information, see http://www.modpython.org/.
 
================================================================================
===>   Registering installation for mod_python-3.3.1_2

接著修改 httpd.conf,加入以下設定,讓 Apache 支援 Python:

LoadModule python_module libexec/apache22/mod_python.so

(mod_python 安裝之後,在 /usr/local/libexec/apache22/ 目錄下會多了一個 mod_python.so)

然後再依據安裝完之後的說明設定便可,比如說要在目錄 /some/directory/ 下運行 Python,則設定如下:

<Directory /some/directory/>
    AddHandler mod_python .py
    PythondHandler python
    PythonDebug On
</Directory>

Limiting open port RST response from XXX to 200 packets/sec

星期三, 八月 12th, 2009

還是那台爆量的伺服器,系統出現以下訊息:

Limiting open port RST response from 253 to 200 packets/sec
Limiting open port RST response from 392 to 200 packets/sec
Limiting open port RST response from 924 to 200 packets/sec
Limiting open port RST response from 689 to 200 packets/sec
Limiting open port RST response from 284 to 200 packets/sec
Limiting open port RST response from 398 to 200 packets/sec
Limiting open port RST response from 219 to 200 packets/sec
Limiting open port RST response from 224 to 200 packets/sec
Limiting open port RST response from 223 to 200 packets/sec
Limiting open port RST response from 425 to 200 packets/sec
Limiting open port RST response from 436 to 200 packets/sec
Limiting open port RST response from 600 to 200 packets/sec
Limiting open port RST response from 265 to 200 packets/sec
Limiting open port RST response from 693 to 200 packets/sec
Limiting open port RST response from 263 to 200 packets/sec
Limiting open port RST response from 505 to 200 packets/sec
Limiting open port RST response from 355 to 200 packets/sec
Limiting open port RST response from 225 to 200 packets/sec
Limiting open port RST response from 228 to 200 packets/sec
Limiting open port RST response from 370 to 200 packets/sec
Limiting open port RST response from 344 to 200 packets/sec
Limiting open port RST response from 288 to 200 packets/sec
Limiting open port RST response from 287 to 200 packets/sec
Limiting open port RST response from 359 to 200 packets/sec
Limiting open port RST response from 355 to 200 packets/sec
Limiting open port RST response from 702 to 200 packets/sec
Limiting open port RST response from 299 to 200 packets/sec
Limiting open port RST response from 345 to 200 packets/sec
Limiting open port RST response from 329 to 200 packets/sec
Limiting open port RST response from 332 to 200 packets/sec
Limiting open port RST response from 211 to 200 packets/sec
Limiting open port RST response from 462 to 200 packets/sec
Limiting open port RST response from 295 to 200 packets/sec
Limiting open port RST response from 800 to 200 packets/sec
Limiting open port RST response from 623 to 200 packets/sec
Limiting open port RST response from 416 to 200 packets/sec
Limiting open port RST response from 256 to 200 packets/sec
Limiting open port RST response from 578 to 200 packets/sec
Limiting open port RST response from 443 to 200 packets/sec
Limiting open port RST response from 264 to 200 packets/sec
Limiting open port RST response from 656 to 200 packets/sec
Limiting open port RST response from 649 to 200 packets/sec
Limiting open port RST response from 426 to 200 packets/sec
Limiting open port RST response from 444 to 200 packets/sec
Limiting open port RST response from 334 to 200 packets/sec
Limiting open port RST response from 240 to 200 packets/sec
Limiting open port RST response from 289 to 200 packets/sec
Limiting open port RST response from 236 to 200 packets/sec
Limiting open port RST response from 600 to 200 packets/sec
Limiting open port RST response from 319 to 200 packets/sec
Limiting open port RST response from 286 to 200 packets/sec
Limiting open port RST response from 363 to 200 packets/sec
Limiting open port RST response from 1279 to 200 packets/sec
Limiting open port RST response from 416 to 200 packets/sec
Limiting open port RST response from 688 to 200 packets/sec
Limiting open port RST response from 771 to 200 packets/sec
Limiting open port RST response from 971 to 200 packets/sec
Limiting open port RST response from 603 to 200 packets/sec
Limiting open port RST response from 228 to 200 packets/sec
Limiting open port RST response from 254 to 200 packets/sec
Limiting open port RST response from 326 to 200 packets/sec
Limiting open port RST response from 441 to 200 packets/sec
Limiting open port RST response from 315 to 200 packets/sec
Limiting open port RST response from 357 to 200 packets/sec
Limiting open port RST response from 591 to 200 packets/sec
Limiting open port RST response from 300 to 200 packets/sec
Limiting open port RST response from 325 to 200 packets/sec
Limiting open port RST response from 332 to 200 packets/sec
Limiting open port RST response from 281 to 200 packets/sec
Limiting open port RST response from 302 to 200 packets/sec
Limiting open port RST response from 560 to 200 packets/sec
Limiting open port RST response from 368 to 200 packets/sec
Limiting open port RST response from 459 to 200 packets/sec
Limiting open port RST response from 388 to 200 packets/sec
Limiting open port RST response from 349 to 200 packets/sec

從網上找到一篇好文章,解釋的十分清楚:
Limiting open port RST response from 952 to 200 packets per second

Apache 之謎樣 ServerLimit 指令 (directive)

星期三, 八月 12th, 2009

最近某個客戶網站的流量暴增,需要將 Apache 的 MaxClients 調高以應付暴增的連線數。
調高之後先用 apachectl configtest 測試一下,結果出現以下的訊息:

WARNING: MaxClients of 300 exceeds ServerLimit value of 256 servers,
 lowering MaxClients to 256.  To increase, please see the ServerLimit
 directive.

組態檔裡沒看到 ServerLimit 的說明,但在官方網站上找到了 ServerLimit Directive 的說明,於是在 httpd-mpm.conf 裡先把 ServerLimit 設定成 500 試試看:

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          300
    MaxRequestsPerChild   0
    ServerLimit         500    # 新設定
</IfModule>

但執行 apachectl configtest 卻還是出現同樣的錯誤訊息?

而後總算在網友的文章Apache 2.0 中 prefork.c 模組與 worker.c 模組的比較中找到端倪:
ServerLimit 要放在 MaxClients 前面!!!
改成下面這樣就可以了:

<IfModule mpm_prefork_module>
    ServerLimit         500    # ServerLimit 放在 MaxClients 前面!!!
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          300
    MaxRequestsPerChild   0
</IfModule>

另外,調整之後如果以 apachectl graceful 重開 Apache,ServerLimit 的設定並不會生效,log 檔裡會出現以下的錯誤訊息:

[Wed Aug 11 22:31:41 2009] [warn] WARNING: Attempt to change ServerLimit ignored during restart

如果以 apachectl restart 重開也沒用,一樣會出現前面提過的錯誤訊息:

WARNING: MaxClients of 300 exceeds ServerLimit value of 256 servers,
 lowering MaxClients to 256.  To increase, please see the ServerLimit
 directive.

在前面提過的官網說明中有一段隱晦的說明:

Any attempts to change this directive during a restart will be ignored, but MaxClients can be modified during a restart.

因此要使 ServerLimit 生效,必須先停止 Apache: apachectl stop,再開啟 Apache: apachectl start

從 Apache Log 中找出連線前 10 名的 IP

星期二, 六月 9th, 2009

語法如下:

cat httpd-access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -
10

如果要查前 20 名或前 n 名,只要將上述語法中的 10 換成想要的數字便可。

Apache 2.2 + php 4.4.8 安裝問題

星期六, 三月 1st, 2008

前幾天 FreeBSD 7.0 終於釋出了,剛好有伺服器可以灌。想說 php 的部分不能升級成 php5,但至少 Apache 可以改裝 Apache 2.2。
但沒想到一裝完 Apache 卻開不起來,執行 apachectl start 之後出現錯誤訊息:
No such file or directory: Failed to enable the 'httpready' Accept Filter
解法請見:
1. http://jerome.anyday.com.tw/archives/64
2. http://mlab.net/freebsd.php#apache

之後執行 apachectl start 卻一點反應也沒有? Apache 還是沒起來。
一看 httpd-error.log 卻看到以下訊息:
[warn] Init: Session Cache is not configured [hint: SSLSessionCache]
解法請見:
http://mlab.net/freebsd.php#php

繼續閱讀 »

Ubuntu Apache2 userdir -> a2enmod -> force-reload

星期四, 十一月 1st, 2007

某台 Ubuntu 7.04 上的 Apache2 要開啟 userdir 的功能。
確認有 userdir 模組,也用 ln 在 /etc/apache2/mods-enabled/ 下增加 link,但執行 apache2ctl graceful 卻一直沒效果?

後來上網查發現 Apaceh2 多了一個 a2enmod 指令,直接下
a2enmod userdir
就會自動把 uerdir 模組的連結加到 /etc/apache2/mods-enabled/ 目錄下。

於是把剛剛自己加的 link 移到,換用 a2enmod 啟用 userdir,
執行之後跟自己加 link 沒多大差異,
不過最後顯示的訊息倒是讓我發現之前是哪做錯了
Module userdir installed; run /etc/init.d/apache2 force-reload to enable.

之前設定好之後是用 apache2ctl graceful 重開,
但我的連線對應到的仍是舊的 Apache 設定,因此一直沒有看到效果。
改用 apache2ctl force-reload 強制重開之後,一切就 ok 了~

Apache Log 出現 /_vti_bin/owssvr.dll 與 /MSOffice/cltreq.asp

星期二, 七月 17th, 2007

察看 Apache Log 檔時看到奇怪的訊息:

[Sat Jul 16 11:53:25 2007] [error] [client XXX.XXX.XXX.XXX] File does not exist: /_vti_bin/owssvr.dll
[Sat Jul 16 11:53:25 2007] [error] [client XXX.XXX.XXX.XXX] File does not exist: /MSOffice/cltreq.asp

用 Google 查了一下,發現原來是 IE 工具列上的「討論」的關係。
如果網友有開啟 IE 的「討論」功能,
連到網站時就會自動去取得 /_vti_bin/owssvr.dll 和 /MSOffice/cltreq.asp 這兩個檔案。
(這個「討論」的功能,要安裝 Microsoft Office 才會有。)
IE Toolbar - Discuss
實際測試看看,連到網頁後點一下那個「討論」的按鈕,
再看 Apache 的 Log 檔,果然出現上面的錯誤訊息。

原文出處:

http://www.webmasterworld.com/forum23/637.htm

http://lists.jammed.com/incidents/2001/10/0127.html