Submitted by felix on 2007, November 16, 11:51 AM. 豬之技術
這篇文章是綜合參考了好幾篇文章寫成的,在此對幾位作者表示感謝,以下是參考的幾篇原文地址:
http://blog.51766.com/page/zsc?entry=1141808884223
http://www.cublog.cn/u/1589/showart.php?id=239748
http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg20921.html
linux下解決apache不支援中文名的方法詳解如下:
■ 下載相關檔案並解壓
WebDAV Resources JP有Apache2對應的mod_encoding的最新版本下載
# wget http://webdav.todo.gr.jp/download/mod_encoding-20021209.tar.gz
# wget http://webdav.todo.gr.jp/download/experimental/mod_encoding.c.apache2.20040616
# tar zxfv mod_encoding-20021209.tar.gz
# cp mod_encoding.c.apache2.20040616 mod_encoding-20021209/mod_encoding.c
■ iconv_hook編譯和安裝
安裝mod_encoding前首先需要安裝iconv_hook。
$ cd mod_encoding-20021209/lib
$ ./configure
$ make
$ su
# make install
完成上面操作後,iconv_hook相關so檔案放到/usr/local/lib下面。
要作業系統系統能夠搜尋到該so檔案,需要完成一下幾行操作
開啟/etc/ld.so.conf檔案,添加一行指向iconv_book的所在路徑,即"/usr/local/lib"
# vi /etc/ld.so.conf
/usr/local/lib
[Esc]、[:]、[w]、[q] 儲存退出。
# PATH="$PATH:/sbin"
# ldconfig
■ apxs工具安裝
編譯mod_encoding時,必須要有apxs,httpd-devel中包括建立和安裝擴充模組的apxs工具。如果是你安裝了Apache,檢查${APACHE_HOME}/bin/下是否存在apxs,如果存在則略過該步無需自己安裝該程式包,如果尚未安裝e則需要自己手動安裝httpd-devel。
# apt-get install http-devel
■ mod_encoding模組的編譯
進入mod_encoding-20021209.tar.gz的解壓目錄,即mod_encoding-20021209
# ./configure --with-apxs=/usr/sbin/apxs --with-iconv-hook=/usr/local/include
# make
我在執行make命令編譯時間,會報如下錯誤:
/usr/local/apache2/bin/apxs -c -I/usr/local/include -liconv_hook mod_encoding.c
/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/include -c -o mod_encoding.lo mod_encoding.c && touch mod_encoding.slo
mod_encoding.c: In function `get_client_encoding':
mod_encoding.c:174: warning: assignment makes pointer from integer without a cast
mod_encoding.c:181: `regex_t' undeclared (first use in this function)
mod_encoding.c:181: (Each undeclared identifier is reported only once
mod_encoding.c:181: for each function it appears in.)
mod_encoding.c:181: parse error before ')' token
mod_encoding.c: At top level:
mod_encoding.c:187: parse error before "return"
mod_encoding.c: In function `set_server_encoding':
mod_encoding.c:213: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `add_client_encoding':
mod_encoding.c:239: `REG_EXTENDED' undeclared (first use in this function)
mod_encoding.c:239: `REG_ICASE' undeclared (first use in this function)
mod_encoding.c:239: `REG_NOSUB' undeclared (first use in this function)
mod_encoding.c:244: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `default_client_encoding':
mod_encoding.c:270: warning: assignment makes pointer from integer without a cast
mod_encoding.c: At top level:
mod_encoding.c:301: warning: initialization from incompatible pointer type
mod_encoding.c:305: warning: initialization from incompatible pointer type
mod_encoding.c:309: warning: initialization from incompatible pointer type
mod_encoding.c:313: warning: initialization from incompatible pointer type
mod_encoding.c:317: warning: initialization from incompatible pointer type
mod_encoding.c: In function `mod_enc_parse':
mod_encoding.c:499: warning: passing arg 2 of `ap_pbase64encode' makes pointer from integer without a cast
mod_encoding.c:501: warning: passing arg 3 of `apr_table_set' makes pointer from integer without a cast
apxs:Error: Command failed with rc=65536
.
make: *** [mod_encoding.so] Error 1
原因很明顯,是regex.h未包含進來,解決辦法也很簡單,用vi開啟mod_encoding.c,
在#include <httpd.h>那一段的前面加上如下一行:
#include <regex.h>
再編譯應該就可以通過了,不過很奇怪,我的機器上面又出現了新的錯誤:
/usr/local/apache2/bin/apxs -c -I/usr/local/include -liconv_hook mod_encoding.c
/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic
-DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2
-pthread -I/usr/local/apache2/include -I/usr/local/apache2/include
-I/usr/local/apache2/include -I/usr/local/include -c -o mod_encoding.lo
mod_encoding.c && touch mod_encoding.slo
In file included from mod_encoding.c:17:
/usr/include/regex.h:362: parse error before "size_t"
/usr/include/regex.h:369: parse error before ':' token
/usr/include/regex.h:378: parse error before ':' token
/usr/include/regex.h:382: parse error before ':' token
/usr/include/regex.h:386: parse error before ':' token
/usr/include/regex.h:390: parse error before ':' token
/usr/include/regex.h:393: parse error before ':' token
/usr/include/regex.h:396: parse error before ':' token
/usr/include/regex.h:461: parse error before "size_t"
/usr/include/regex.h:554: parse error before "size_t"
/usr/include/regex.h:556: parse error before "regerror"
/usr/include/regex.h:557: parse error before "size_t"
mod_encoding.c: In function `get_client_encoding':
mod_encoding.c:175: warning: assignment makes pointer from integer without a cast
mod_encoding.c:182: warning: passing arg 1 of `ap_regexec' from incompatible pointer type
mod_encoding.c: In function `set_server_encoding':
mod_encoding.c:214: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `add_client_encoding':
mod_encoding.c:245: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `default_client_encoding':
mod_encoding.c:271: warning: assignment makes pointer from integer without a cast
mod_encoding.c: At top level:
mod_encoding.c:302: warning: initialization from incompatible pointer type
mod_encoding.c:306: warning: initialization from incompatible pointer type
mod_encoding.c:310: warning: initialization from incompatible pointer type
mod_encoding.c:314: warning: initialization from incompatible pointer type
mod_encoding.c:318: warning: initialization from incompatible pointer type
mod_encoding.c: In function `mod_enc_parse':
mod_encoding.c:500: warning: passing arg 2 of `ap_pbase64encode' makes pointer from integer without a cast
mod_encoding.c:502: warning: passing arg 3 of `apr_table_set' makes pointer from integer without a cast
apxs:Error: Command failed with rc=65536
.
make: *** [mod_encoding.so] Error 1
(這個問題我暫還未解決,如果解決了,我會再來更新此段)
#ls -l mod_encoding.o
查看是否已經產生了mod_encoding.o檔案,如果是,則make成功繼續下邊的操作。
# gcc -shared -o mod_encoding.so mod_encoding.o -Wc,-Wall -L/usr/local/lib -Llib -liconv_hook
產生mod_encoding.so檔案,將該檔案拷貝到你的模組存放目錄,一般為${APACHE_HOME}/modules/
# cp mod_encoding.so /usr/local/apache/modules/mod_encoding.so
■ httpd.confd的設定
這個是我的設定檔案,參考的ytang的
LoadModule headers_module modules/mod_headers.so
LoadModule encoding_module modules/mod_encoding.so
<IfModule mod_headers.c>
Header add MS-Author-Via "DAV"
</IfModule>
<IfModule mod_encoding.c>
EncodingEngine on
NormalizeUsername on
SetServerEncoding GBK
DefaultClientEncoding UTF-8 GBK GB2312
AddClientEncoding "(Microsoft .* DAV $)" UTF-8 GBK GB2312
AddClientEncoding "Microsoft .* DAV" UTF-8 GBK GB2312
AddClientEncoding "Microsoft-WebDAV*" UTF-8 GBK GB2312
</IfModule>
轉自 一個IT工人的技術門戶 -- http://itworker.buylog.cn