<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Apache on mwclabs</title><link>https://mwclabs.net/tags/apache/</link><description>Recent content in Apache on mwclabs</description><generator>Hugo</generator><language>en</language><copyright>&lt;a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener">CC BY-NC 4.0&lt;/a></copyright><lastBuildDate>Fri, 21 Feb 2014 17:49:41 -0300</lastBuildDate><atom:link href="https://mwclabs.net/tags/apache/index.xml" rel="self" type="application/rss+xml"/><item><title>Fix origin IP address in Apache access log when behind a proxy</title><link>https://mwclabs.net/posts/2014/02/fix-origin-ip-address-in-apache-access-log-when-behind-a-proxy/</link><pubDate>Fri, 21 Feb 2014 17:49:41 -0300</pubDate><guid>https://mwclabs.net/posts/2014/02/fix-origin-ip-address-in-apache-access-log-when-behind-a-proxy/</guid><description>&lt;p>When your app is behind any sort of reverse proxy (like a Load Balancer, API Gateway, CDN, etc), by default, the Apache access log will start showing the proxy&amp;rsquo;s IP address as the origin instead of the client one.&lt;/p>
&lt;p>Most of those proxies append the client IP address to the &lt;code>X-Forwarded-For&lt;/code> HTTP header, so we can use it to get the IP into the access log using a &lt;code>CustomLog&lt;/code> as seen below:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-apache" data-lang="apache">&lt;span style="display:flex;">&lt;span>LogFormat &lt;span style="color:#e6db74">&amp;#34;%{X-Forwarded-For}i %l %u %t \&amp;#34;%r\&amp;#34; %&amp;gt;s %b \&amp;#34;%{Referer}i\&amp;#34; \&amp;#34;%{User-Agent}i\&amp;#34;&amp;#34;&lt;/span> proxy
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>SetEnvIf X-Forwarded-For &lt;span style="color:#e6db74">&amp;#34;^.*\..*\..*\..*&amp;#34;&lt;/span> forwarded
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>CustomLog ${APACHE_LOG_DIR}/mywebsite_access.log combined env=!forwarded
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>CustomLog ${APACHE_LOG_DIR}/mywebsite_access.log proxy env=forwarded
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;em>Reference:&lt;/em> &lt;a href="https://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html">https://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html&lt;/a>&lt;/p></description></item></channel></rss>