<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[前端Nginx，后端Apache获取用户真实IP地址]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Tue, 08 Sep 2015 02:09:07 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：这位兄弟做的lnmp包细节上不错，不支持hhvm，最主要是这位兄弟其服务意识好，之前有一个lnmp.org，我觉得都挺不错，这块主要是对nginx代码了apache后，apache如何获取ip这块是个大问题，需要一些模块来设置的一个配置，对来源IP有一个日志需求很正常，这块像Tencent的TGW，其实在这一块从一个大的IP进来分到后面的机器处理，到底落到哪台机器了，及IP是多少，也涉及到这些类似问题，对于此种架构来讲，没有过实际生产经验，仅供参考，一般直接从硬件如F5，或lvs代理到apache或nginx，我想这个哥们的应用场景可能不大一样吧。<br/><br/>Internet -&gt; Nginx -&gt; Apache<br/>最近在将Apache-2.2和Apache-2.4添加到《lnmp一键安装包》中，Nginx作为前端，Apache作为后端的情况下，Apache只能获取到Nginx前端的ip地址（127.0.0.1），而无法获取到用户的真实ip地址，在这种情况下，后端是Apache如何获取用户真实IP地址？<br/><br/>Nginx配置如下：<br/><br/>location / &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try_files $uri @apache;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>location @apache &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;internal;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass http://127.0.0.1:8080;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include proxy.conf;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>location ~ .*&#92;.(php&#124;php5)?$&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass http://127.0.0.1:8080;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include proxy.conf;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>proxy_connect_timeout 300s;<br/>proxy_send_timeout 900;<br/>proxy_read_timeout 900;<br/>proxy_buffer_size 32k;<br/>proxy_buffers 4 64k;<br/>proxy_busy_buffers_size 128k;<br/>proxy_redirect off;<br/>proxy_hide_header Vary;<br/>proxy_set_header Accept-Encoding &#039;&#039;;<br/>proxy_set_header Referer $http_referer;<br/>proxy_set_header Cookie $http_cookie;<br/>proxy_set_header Host $host;<br/>proxy_set_header X-Real-IP $remote_addr;<br/>proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br/>获取真实IP地址有Apache有2个模块：<br/>mod_rpaf：Apache-2.2支持；Apache-2.4不支持。网上教程很多<br/>mod_remoteip：Apache-2.4自带模块；Apache-2.2支持；推荐<br/><br/>Apache-2.2.25<br/>mod_rpaf模块<br/><br/>wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz<br/>tar -xzvf mod_rpaf-0.6.tar.gz<br/>cd mod_rpaf-0.6/<br/>/usr/local/apache/bin/apxs&nbsp;&nbsp;-i -c -n mod_rpaf-2.0.slo mod_rpaf-2.0.c<br/>添加Apache配置<br/><br/>vi&nbsp;&nbsp;/usr/local/apache/conf/httpd.conf<br/>Include conf/extra/httpd-rpaf.conf<br/>vi /usr/local/apache/conf/extra/httpd-rpaf.conf<br/><br/>LoadModule rpaf_module&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modules/mod_rpaf-2.0.so<br/>RPAFenable On<br/>RPAFsethostname On<br/>RPAFproxy_ips 127.0.0.1 10.8.0.110 # 代理服务器的ip地址（记得做相应修改）<br/>RPAFheader X-Forwarded-For<br/>备注：RPAFproxy_ips后面添加代理服务器的ip地址,有几个填几个<br/>测试<br/><br/># /usr/local/apache/bin/apachectl -t<br/># /usr/local/apache/bin/apachectl restart<br/># 看日志<br/>mod_remoteip<br/>Apache-2.2下配置mod_remoteip如下：<br/>安装<br/><br/>wget https://github.com/ttkzw/mod_remoteip-httpd22/raw/master/mod_remoteip.c<br/>/usr/local/apache/bin/apxs -i -c -n mod_remoteip.so mod_remoteip.c<br/>修改配置文件：<br/><br/>vi /usr/local/apache/conf/httpd.conf<br/>Include conf/extra/httpd-remoteip.conf<br/>vi /usr/local/apache/conf/extra/httpd-remoteip.conf<br/>LoadModule remoteip_module modules/mod_remoteip.so<br/>RemoteIPHeader X-Forwarded-For<br/>RemoteIPInternalProxy 127.0.0.1<br/>测试：<br/><br/># /usr/local/apache/bin/apachectl -t<br/># /usr/local/apache/bin/apachectl restart<br/># 看日志<br/>Apache-2.4配置mod_remoteip除了上面（自带mod_remoteip模块不需要安装），还需要修改日志格式（折腾很久）<br/><br/>LogFormat &quot;%h %a %l %u %t &#92;&quot;%r&#92;&quot; %&gt;s %b &#92;&quot;%&#123;Referer&#125;i&#92;&quot; &#92;&quot;%&#123;User-Agent&#125;i&#92;&quot;&quot; combined<br/>LogFormat &quot;%h %a %l %u %t &#92;&quot;%r&#92;&quot; %&gt;s %b&quot; common<br/>LogFormat &quot;%h %l %u %t &#92;&quot;%r&#92;&quot; %&gt;s %b &#92;&quot;%&#123;Referer&#125;i&#92;&quot; &#92;&quot;%&#123;User-Agent&#125;i&#92;&quot; %I %O&quot; combinedi<br/>在日志格式中加上%a<br/><br/>摘自：https://blog.linuxeye.com/378.html<br/><br/>Q:这里是老大的教程，但最后有一个修改日志格式的教程，请问日志格式在哪修改，文件路径是什么啊？<br/>那最后面 Apache-2.4配置mod_remoteip除了上面（自带mod_remoteip模块不需要安装），还需要修改日志格式（折腾很久），这里的日志格式在哪里修改呢，谢谢？<br/>A:请看这文章：http://blog.sina.com.cn/s/blog_672c5a470100xj7z.html
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 前端Nginx，后端Apache获取用户真实IP地址]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>