如果你的后端是Apache 2.4.X,那么在编译mod_rpaf-0.6时,一定会出现下面这个错误的。
1 2 3 4 5 6 7 8 9 10 11 12 | 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 |
这是因为Apache 2.4.X的api已经改变了,而mod_rpaf又没有更新导致,可以手动更新了mod_rpaf-2.0.c文件再编译就好了
1 2 3 | sed -i 's/remote_addr/client_addr/' mod_rpaf-2.0.c sed -i 's/remote_ip/client_ip/' mod_rpaf-2.0.c /usr/local/apache/bin/apxs -i -c -n mod_rpaf-2.0.slo mod_rpaf-2.0.c |
然后修改httpd.conf配置文件
1 2 3 4 5 6 7 | LoadModule rpaf_module /usr/lib/apache/mod_rpaf-2.0.so <ifmodule mod_rpaf.c> RPAFenable On RPAFsethostname On RPAFproxy_ips 127.0.0.1 RPAFheader X-Forwarded-For </ifmodule> |
其实Apache 2.4.X已经自带了一个新的获取前端IP的模块,还是官方的!在Apache 2.4.X源码包里面
1 | httpd-2.4.X/modules/metadata/mod_remoteip.c |
不想下载Apache 2.4.X,也可以直接下载mod_remoteip.c的
1 2 | wget https://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/metadata/mod_remoteip.c /usr/local/apache/bin/apxs -cia mod_remoteip.c |
最后修改httpd.conf配置文件
1 2 3 | LoadModule remoteip_module /usr/lib/apache/mod_remoteip.so RemoteIPHeader X-Real-IP RemoteIPInternalProxy 127.0.0.1 |