故障描述:外网有一台apache服务器提供软件给客户下载,因为很多软件名是带有中文的,所以下载的时候失败,临时的解决方案是将中文名修改为一个英文名就OK了,但是这只是一时的解决步骤,最终的方案就是让apache支持中文软件名文件下载。
环境描述:
系统:红帽4.8 apache版本:2.2.11
不知道apache版本的哥们可以用如下命令参考:
/usr/local/apache2/bin/apachectl -v
1、先确认mod_headers已经静态编译到apache中。
grep headers /usr/local/apache2/conf/httpd.conf
如果没有输出,那么你没有编译mod_headers到apache
解决办法:
解决办法:
下载和你apache版本相对应的源码包,下载后解压到当前目录
tar zxvf httpd-2.2.11.tar.gz
cd httpd-2.2.11/modules/metadata
/usr/local/apache2/bin/apxs -i -a -c mod_headers.c
编译完成之后,再确认一下httpd.conf是否有mod_headers.so文件,如果有则说明已经加载成功!
grep headers /usr/local/apache2/conf/httpd.conf
LoadModule headers_module modules/mod_headers.so
LoadModule headers_module modules/mod_headers.so
2、下载相关文件并解压
WebDAV Resources JP有Apache2对应的mod_encoding的最新版本下载
wget http://webdav.todo.gr.jp/download/experimental/mod_encoding.c.apache2.20040616
wget http://webdav.todo.gr.jp/download/mod_encoding-20021209.tar.gz
tar zxfv mod_encoding-20021209.tar.gz
cp mod_encoding.c.apache2.20040616 mod_encoding-20021209/mod_encoding.c
3、iconv_hook编译和安装,安装mod_encoding前首先需要安装iconv_hook。
wget http://webdav.todo.gr.jp/download/mod_encoding-20021209.tar.gz
tar zxfv mod_encoding-20021209.tar.gz
cp mod_encoding.c.apache2.20040616 mod_encoding-20021209/mod_encoding.c
3、iconv_hook编译和安装,安装mod_encoding前首先需要安装iconv_hook。
cd mod_encoding-20021209/lib
./configure
make
mke install
完成上面操作后,iconv_hook相关的so文件放到/usr/local/lib下面。
要系统能够搜索到该so文件,需要让他自动加载
vi /etc/ld.so.conf
增加如下内容:
/usr/local/lib
增加完后执行如下命令:
PATH="$PATH:/sbin"
ldconfig
3、mod_encoding模块的编译安装
cd mod_encoding-20021209
./configure --with-apxs=/usr/local/apache2/bin/apxs --with-iconv-hook=/usr/local/include
make
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 -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:228: warning: assignment makes pointer from integer without a cast
mod_encoding.c:235: error: `regex_t' undeclared (first use in this function)
mod_encoding.c:235: error: (Each undeclared identifier is reported only once
mod_encoding.c:235: error: for each function it appears in.)
mod_encoding.c:235: error: syntax error before ')' token
mod_encoding.c: At top level:
mod_encoding.c:241: error: syntax error before "return"
mod_encoding.c: In function `set_server_encoding':
mod_encoding.c:267: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `add_client_encoding':
mod_encoding.c:293: error: `REG_EXTENDED' undeclared (first use in this function)
mod_encoding.c:293: error: `REG_ICASE' undeclared (first use in this function)
mod_encoding.c:293: error: `REG_NOSUB' undeclared (first use in this function)
mod_encoding.c:298: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `default_client_encoding':
mod_encoding.c:324: warning: assignment makes pointer from integer without a cast
mod_encoding.c: At top level:
mod_encoding.c:355: warning: initialization from incompatible pointer type
mod_encoding.c:359: warning: initialization from incompatible pointer type
mod_encoding.c:363: warning: initialization from incompatible pointer type
mod_encoding.c:367: warning: initialization from incompatible pointer type
mod_encoding.c:371: warning: initialization from incompatible pointer type
mod_encoding.c: In function `mod_enc_parse':
mod_encoding.c:553: warning: passing arg 2 of `ap_pbase64encode' makes pointer from integer without a cast
mod_encoding.c:555: 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] 错误 1
解决该错误很简单,打开mod_encoding.c文件
/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_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:228: warning: assignment makes pointer from integer without a cast
mod_encoding.c:235: error: `regex_t' undeclared (first use in this function)
mod_encoding.c:235: error: (Each undeclared identifier is reported only once
mod_encoding.c:235: error: for each function it appears in.)
mod_encoding.c:235: error: syntax error before ')' token
mod_encoding.c: At top level:
mod_encoding.c:241: error: syntax error before "return"
mod_encoding.c: In function `set_server_encoding':
mod_encoding.c:267: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `add_client_encoding':
mod_encoding.c:293: error: `REG_EXTENDED' undeclared (first use in this function)
mod_encoding.c:293: error: `REG_ICASE' undeclared (first use in this function)
mod_encoding.c:293: error: `REG_NOSUB' undeclared (first use in this function)
mod_encoding.c:298: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `default_client_encoding':
mod_encoding.c:324: warning: assignment makes pointer from integer without a cast
mod_encoding.c: At top level:
mod_encoding.c:355: warning: initialization from incompatible pointer type
mod_encoding.c:359: warning: initialization from incompatible pointer type
mod_encoding.c:363: warning: initialization from incompatible pointer type
mod_encoding.c:367: warning: initialization from incompatible pointer type
mod_encoding.c:371: warning: initialization from incompatible pointer type
mod_encoding.c: In function `mod_enc_parse':
mod_encoding.c:553: warning: passing arg 2 of `ap_pbase64encode' makes pointer from integer without a cast
mod_encoding.c:555: 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] 错误 1
解决该错误很简单,打开mod_encoding.c文件
找到如下内容:
#include
在上述内容中增加如下内容:
#include
再重新./configure,make即可!如果还不行那上网查相关资料吧!
查看是否在当前目录下是否生成了mod_encoding.o文件,生成后继续执行如下命令:
gcc -shared -o mod_encoding.so mod_encoding.o -Wc,-Wall -L/usr/local/lib -Llib -liconv_hook
执行上述命令后不会有任何输出提示,再次确认是否生成了mod_encoding.so文件,并将该文件拷贝到你自己的apache的模块存放目录,我的就是/usr/local/apache2/modules
执行上述命令后不会有任何输出提示,再次确认是否生成了mod_encoding.so文件,并将该文件拷贝到你自己的apache的模块存放目录,我的就是/usr/local/apache2/modules
cp mod_encoding.so /usr/local/apache2/modules/mod_encoding.so
4、httpd.conf文件增加如下内容是为了更好的支持中文软件名称:
4、httpd.conf文件增加如下内容是为了更好的支持中文软件名称:
LoadModule encoding_module modules/mod_encoding.so
Header add MS-Author-Via "DAV"
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
5、重新启动apache,将带有中文名称的软件放到你的web服务器的发布目录下测试是否可以正常下载?
Header add MS-Author-Via "DAV"
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
5、重新启动apache,将带有中文名称的软件放到你的web服务器的发布目录下测试是否可以正常下载?
6、我这里小测试一下: