王志明

Apache安装mod_rpaf模块

这两天配置Nginx反代Apache,但是有个问题折腾好久,Nginx反代Apache之后,Apache日志无法获取访问者真实IP地址,php中$_SERVER[‘REMOTE_ADDR’]也无法获取真实IP。 搜集了些资料安装 mod_rpaf 模块可以解决Apache日志问题。 php 的 $_SERVER[‘REMOTE_ADDR’] 无法没有解决。


安装:

apache2.4以下版本安装:

[root@server mod_rpaf-0.6]# wget http://mirror.trouble-free.net/sources/mod_rpaf-0.6.tar.gz
[root@server mod_rpaf-0.6]# tar xzvf mod_rpaf-0.6.tar.gz
[root@server mod_rpaf-0.6]# cd mod_rpaf-0.6
[root@server mod_rpaf-0.6]# apxs -c -i -a mod_rpaf-2.0.c

apache2.4版本安装: apache2.4安装时会出现错误

[root@server mod_rpaf-0.6]# apxs -c -i -a mod_rpaf-2.0.c
/var/www/build/libtool --silent --mode=compile gcc -std=gnu99 -prefer-pic   -DLINUX -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/include/apache  -I/usr/include/apache   -I/usr/include/apache   -c -o mod_rpaf-2.0.lo mod_rpaf-2.0.c && touch mod_rpaf-2.0.slo
mod_rpaf-2.0.c: In function 'rpaf_cleanup':
mod_rpaf-2.0.c:150: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:151: error: 'conn_rec' has no member named 'remote_addr'
mod_rpaf-2.0.c:151: warning: implicit declaration of function 'inet_addr'
mod_rpaf-2.0.c:151: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c: In function 'change_remote_ip':
mod_rpaf-2.0.c:164: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:183: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:186: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:187: error: 'conn_rec' has no member named 'remote_addr'
mod_rpaf-2.0.c:187: error: 'conn_rec' has no member named 'remote_ip'
apxs:Error: Command failed with rc=65536

apache2.4版本正确安装:

[root@server mod_rpaf-0.6]# wget http://mirror.trouble-free.net/sources/mod_rpaf-0.6.tar.gz
[root@server mod_rpaf-0.6]# tar xzvf mod_rpaf-0.6.tar.gz
[root@server mod_rpaf-0.6]# cd mod_rpaf-0.6
[root@server mod_rpaf-0.6]# git clone git://gist.github.com/2716030.git
[root@server mod_rpaf-0.6]# patch < 2716030/mod_rpaf-2.0.c.patch
[root@server mod_rpaf-0.6]# apxs -c -i -a mod_rpaf-2.0.c

配置:

我的配置文件:

[root@server mod_rpaf-0.6]# cat /etc/httpd/conf.modules.d/mod_rpaf.conf
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1
RPAFheader X-Forwarded-For

参考

http://zh.wikipedia.org/wiki/X-Forwarded-For (X-Forwarded-For 知识) http://www.centos.bz/2011/10/install-mod_rpaf-apache-get-real-ip/ http://baiqiuyi.com/linux/apache-2-4无法安装mod_rpaf.html

<< Older