Archive for the ‘Apache’ Category

让Apache支持中文目录

Sunday, May 18th, 2008

Apache自身并不支持中文目录,但是目前日本的webdev提供了mod_encoding插件来支持多字节目录。
在AS5和Everest0.5pre2版本上测试通过,记录如下:
1)首先确定安装了httpd-devel包。如果没有安装之
2)从官方分别下载基本包和补丁包

#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

或者可以下载文末提供的已经打好补丁的压缩包
3)解压基本包,并用mod_encoding.c.apache2.20040616替代基本包里的mod_encoding.c

#tar -xzf mod_encoding-20021209.tar.gz
#cd mod_encoding-20021209
#cp -f ../mod_encoding.c.apache2.20040616  mod_encoding.c
4)编译安装iconv_look库

# cd mod_encoding-20021209/lib/
# ./configure && make && make install
#echo “/usr/local/lib” >>/etc/ld.so.conf.d/local.conf
#ldconfig
5)编译安装mod_encoding模块

#cd mod_encoding-20021209
#./configure –with-apxs=/usr/sbin/apxs –with-iconv-hook=/usr/local/include
#make

注:如果5)步骤出现下面的报错

mod_encoding.c:235: error: ‘regex_t’ undeclared (first use in this function)

请在mod_encoding.c文件中加上regex.h头,也就是加入
#include <regex.h>
一行。然后再编译。
6)安装动态库
如果前面步骤都没有错误,则应该在当前目录能看到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的动态模块库目录中去

cp mod_encoding.so /usr/local/httpd/modules/

我们采用创建新的conf文件来加载该so文件

#cat >/etc/httpd/conf.d/cndir.conf
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>
<CTRL+D>
当然SetServerEncoding UTF-8这样可以设置成你希望的默认编码,比如GBK,比如GB2312.
重启Apache。现在测试中文目录,看看效果。

Make Apache httpd 2.2.8 in Fedora 8 64bit Failed - libexpat

Saturday, March 22nd, 2008

For whatever reason, you may need to build the Apache httpd from source. Build apache from source file is among the easiest one if you are talking about LAMP. But that’s not the case if you’re building on a 64bit machine. Most probably you’ll get the following message:

/usr/lib/libexpat.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make[3]: *** [libaprutil-1.la] Error 1
make[3]: Leaving directory `/Install/httpd-2.2.8/srclib/apr-util’
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/Install/httpd-2.2.8/srclib/apr-util’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/Install/httpd-2.2.8/srclib’
make: *** [all-recursive] Error 1

The main reason is they don’t like expatriate. No, seriously the main culprit is the /usr/lib/libexpat.so: could not read symbols: File in wrong format. The quick fix is quite simple, just use the internal libexpat by adding –with-expat=builtin when configuring the build.

./configure –prefix=/usr/local/apache2 –enable-module=so –enable-mods-shared=most –with-expat=builtin

Apache2.2.6带宽连接数控制(limitipconn_module+bw_module)

Wednesday, February 20th, 2008

下载模块

http://ivn.cl/files/source/mod_bw-0.8.tgz

使用apxs来添加模块

/usr/local/httpd/bin/apxs -i -a -c mod_bw.c

重启Apache服务器

/usr/local/httpd/bin/apachectl restart

确认模块被正确加载

/usr/local/httpd/bin/httpd -M

使用mod_bandwidth控制Apache的带宽

Tuesday, January 29th, 2008

Apache1.3.7实际上带有mod_bandwidth支持,只是没有此模块的so文件,我们所做的就是下载mod_bandwidth的源文件进行编译,并对mod_bandwidth进行相应的设置。
    在下载之前,请先确认自己的Apache配置文件httpd.conf中是否含有

<IFDEFINE HAVE_BANDWIDTH>
LoadModule bandwidth_module modules/mod_bandwidth.so
</IFDEFINE>

以及

<IFDEFINE HAVE_BANDWIDTH>
AddModule mod_bandwidth.c
</IFDEFINE>

若是没有,请加上

    LoadModule bandwidth_module modules/mod_bandwidth.so

  AddModule mod_bandwidth.c

    并且这两行必须分别加在相应区域的最前面,使得这个模块以最低的优先级运行。(不过1.3.7的Apache应该有,呵呵)。

    确认后,请输入wget.ftp://ftp.cohprog.com/pub/apache/module/1.3.0/mod_bandwidth.c将源文件下载到服务器,然后请使用apxs对其进行编译,编译方法和mod_limitipconn的基本相同,如我输入/usr/sbin/apxs -c mod_bandwidth.c -o /usr/lib/apache(Apache的模块目录),编译程序会自动将编译成功的mod_bandwidth.so文件放到Apache的模块目录,您也可以自己确认一下,若是不正常,拷贝过去即可。

    mod_bandwidth运行时需要一些特定的目录,按照默认情况,请运行以下命令创建并更改目录的权限:

   mkdir /tmp/apachebw

  mkdir /tmp/apachebw/link

  mkdir /tmp/apachebw/master

  chmod -R 777 /tmp/apachebw

    然后再打开httpd.conf文件,加上以下内容

<IFMODULE mod_bandwidth.c>
BandWidthDataDir “/tmp/apachebw/”
BandWidthModule on
</IFMODULE>

    这时,我们就能够对所需要限制带宽的目录进行相应的设置,此处的目录请使用服务器的绝对路径。如我们想限制服务器/home/www/softicp/download/soft目录的下载速度,也就是限制网址http://download.softicp.com/soft目录下软件的下载速度,则为httpd.conf文件增加以下内容

<DIRECTORY soft download softicp www home>
BandWidth cbifamily.com 0 #来自cbifamily.com的下载不受速度限制
BandWidth 210.51.21 0 #来自210.51.21网段的下载不受速度限制
BandWidth all 327680 #来自其它网段的速度都限制为327680Byte,即30KB/s
</DIRECTORY>

  设置完毕后,重新启动Apache服务,即可生效。

    mod_bandwidth还有许多其它有用的参数,如在DIRECTORY和/DIRECTORY中间加上MaxConnection120则可以限制某个目录的最多连接数,当超过指定连接数时,拒绝新的连接,此参数与mod_limitipconn模块结合可以控制某个目录的最多连接人数。

    其它的参数请朋友们到其官方网站http://www.cohprog.com/v3/bandwidth/doc-en.html察看相关的文档。

    Apache的功能确实强大,很多功能都可以通过添加模块来实现,在http://modules.apache.org/可以找到更多的模块,我们也可以编写自己的模块来实现相应的功能。

 

让apache列出文件目录时不截断长文件名

Monday, October 29th, 2007

编辑http.conf文件

在相应的目录加入

IndexOptions +NameWidth=*

CentOS X86-64下安装apache2.2.6

Tuesday, October 9th, 2007

./configure \
LDFLAGS=”-L/usr/lib64 -L/lib64″ \
–prefix=/usr/local/httpd \
–enable-so \
–enable-dav \
–enable-rewrite \
–disable-authn-default \
–disable-authz-default \
–disable-authz-groupfile \
–disable-include \
–disable-filter \
–disable-env \
–disable-setenvif \
–disable-asis \
–disable-cgid \
–disable-cgi \
–disable-negotiation \
–disable-actions \
–disable-userdir \

Apache防止多线程下载

Wednesday, August 15th, 2007

mod_limitipconn.c是一个非官方的apache模块,可以用来作为WEB文件的下载限制
,但是它是使用ExtendedStatus On形式,工作在应用层。当同一个IP的连接到达
限制的时候,apache对get请求发送:

HTTP/1.1 503 Service Temporarily Unavailable

从而使用户不能下载,但并不能阻止这种攻击,仍旧允许连接的。不过这个东东对
网管来说还是很有用的,特别是下载站的网管。简单介绍一下安装(动态模块方式
安装,假设你的apache已经装在/usr/local/httpd目录下):

从http://dominia.org/djao/limitipconn2.html获得最新的limitipconn源代码

 安装方法如下:

#wget http://dominia.org/djao/limit/mod_limitipconn-0.22.tar.gz
#tar -xzvf mod_limitipconn-0.22.tar.gz
#cd mod_limitipconn-0.22
#vi Makefile

修改第一行:

APXS= apxs

改为

APXS= /usr/local/httpd/bin/apxs

#make
#make install

修改apache配置文件:

vi /usr/local/httpd/conf/httpd.conf

把ExtendedStatus On选项打开(服务器必须支持status_module模块)

<Location />
MaxConnPerIP 3 ###限制web根目录同一个IP只能同时开3进程下载

# NoIPLimit image/*
# OnlyIPLimit audio/mpeg video 
</Location>

重启apache服务器