最新消息:宝宝仲的世界......这里是宝宝仲的舞台,宝宝仲的个人Show

linux下解决apache不支持中文名的方法详解!

WEB TECH luinstein 456浏览 0评论

 

这篇文章是综合参考了好几篇文章写成的,在此对几位作者表示感谢,以下是参考的几篇原文地址:
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

转载请注明:宝宝仲的世界 » linux下解决apache不支持中文名的方法详解!

您必须 登录 才能发表评论!