登录|注册|快速了解|帮助

小戴 的维客空间

http://wiki.hudong.com/daiqi/index  ( 复制链接 | 加入收藏夹 )

当前位置: Apache增加Rewrite模块 >> 正文

Apache增加Rewrite模块

以前用默认配置编译并安装了apache2,很多模块都没编入,现在需要使用rewrite的功能。在网上查了一些资料,但实际操作时有些出入,经过一些改正和摸索,终于可以顺利使用了:

环境:
RedHat Linux AS4
Apache2.2.3,使用默认安装目录:/usr/local/apache2

步骤:

1、Apache安装rewrite模块的时候需要DBM支持,否则无法编译。使用rpm -qa gdbm 查询,如果没有,需要先下载并安装gdbm:
下载地址:
ftp://ftp.gnu.org/gnu/gdbm/

安装步骤:
./configure
make
make install
make install-compat (如果不执行此步,无法编译出ndbm.h头文件)

2.更改当前目录到apache源码目录中(俺的是:/home/software/httpd-2.2.3/modules/mappers/),如果不知道mod_rewrite.c在哪个目录,可以使用以下命令查找:
find Your_Apache2_Source_Directiry -name "mod-rewrite.c"

编译rewrite模块:
网上说使用如下命令就可以直接编译得到so文件:
/usr/local/apache2/bin/apxs -c mod-rewrite.c -lgdbm
但偶编译完却没发现 :-( ,只好手工编译一下:
gcc -shared -o mod_rewrite.so mod_rewrite.o -lgdbm
终于得到so文件啦 ^_^

网上有这样一段话:"-lgdbm"是为在编译mod-rewrite.c时要把gdbm连接近来,这样当stop apache再启动时就不会报"dbm fetch"错误.我照做了所以没有什么错误提示,不知道不照做会怎样,等以后有时间了再试一下吧。

3.安装rewrite模块:
/usr/local/apache2/bin/apxs -i -A -n rewrite mod_rewrite.so
该命令把mod_rewrite.so模块安装到apache2的相应目录中(modules),然后在httpd.conf中加入LoadModule指令行。命令中的rewrite参数是告诉apxs命令mod_rewrite.so文件中的模块名。在命令执行后,apxs会在LoadModule中为rewrite加上"_module"以标名模块名称。如果你在启动apache时发现总是给出“不能定位API”之类的错误,那就是说明LoadModule后面的模块名的语法要根据您的apache版本加以改变。

4、停止apache
apache/bin/apachectl stop

5、运行配置文件检查命令
apache/bin/apachectl configtest
如显示Syntax OK,则表示整个操作成功。那么可以到第6步。否则根据提示信息进行调试。但只要按照上面所述操作应该是不会出错的。

6、启动apache
apache/bin/apachectl start

网上说不能使用/usr/local/apache2/bin/apachectl restart来启动apache,否则rewrite功能不启用。但我试了是可以的。

7、检测Apache运行模块
apache/bin/httpd -l

运行模块列表如下:

Compiled in modules:
  core.c
  mod_access.c
  mod_auth.c
  mod_include.c
  mod_log_config.c
  mod_env.c
  mod_setenvif.c
  mod_proxy.c
  proxy_connect.c
  proxy_ftp.c
  proxy_http.c
  prefork.c
  http_core.c
  mod_mime.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_cgi.c
  mod_negotiation.c
  mod_dir.c
  mod_imap.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_rewrite.c
  mod_so.c


参考资料:
--------------
I tried to include in my Apache Web server's configuration the mod_rewrite module, but when I restarted the server, I received an error:

Cannot load /usr/local/apache/libexec/mod_rewrite.so into server:
/usr/local/apache/libexec/mod_rewrite.so: undefined symbol: dbm_fetch
The problem, as it turns out, is that mod_rewrite.so is compiled incorrectly. It should be linked with a dbm library but it isn't.

If you have an up-to-date set of Apache source files, you can easily solve this problem by manually rerunning the last compilation step of this module, using the correct options. When you execute make mod_rewrite.so in the appropriate directory, it performs this final step:

gcc -shared -o mod_rewrite.so mod_rewrite.lo
Rerun gcc, this time adding a reference to the GNU gdbm library:

gcc -shared -o mod_rewrite.so mod_rewrite.lo -lgdbm
Next, copy the newly created mod_rewrite.so over to /usr/local/apache/libexec or wherever your Apache module files are located.

In my case, this was all that was needed to solve the problem. Your mileage may vary.
评论: Apache增加Rewrite模块
     当前尚无网友评论!
发表我的评论
粗体 斜体 下划线 插入超链接 插入表情
Email:
密 码:

验证码:





(请输入图中数字)   看不清,换一个试试
提示
  • 1.遵守国家有关法律、法规,尊重网上道德
  • 2.承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 3.互动百科留言板管理人员有权保留或删除其管辖留言中的任意内容