<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Keyur &#187; Varnish</title>
	<atom:link href="http://keyur.co.in/blog/category/varnish/feed/" rel="self" type="application/rss+xml" />
	<link>http://keyur.co.in</link>
	<description>Just another blog...</description>
	<lastBuildDate>Sun, 28 Apr 2013 07:21:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>Varnish X-Forwarded-for Public IP not visible</title>
		<link>http://keyur.co.in/blog/varnish-x-forwarded-for-public-ip-not-visible/</link>
		<comments>http://keyur.co.in/blog/varnish-x-forwarded-for-public-ip-not-visible/#comments</comments>
		<pubDate>Fri, 26 Apr 2013 03:04:22 +0000</pubDate>
		<dc:creator><![CDATA[Keyur]]></dc:creator>
				<category><![CDATA[Varnish]]></category>

		<guid isPermaLink="false">http://keyur.co.in/?p=70</guid>
		<description><![CDATA[This post describes under which scenario you may not see X- Forwarded-for public IP in your Varnish / Apache logs and How to resolve the same. If you have a website doing Country detection based on IP address then it may &#8230; <a href="http://keyur.co.in/blog/varnish-x-forwarded-for-public-ip-not-visible/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>This post describes under which scenario you may not see X- Forwarded-for public IP in your Varnish / Apache logs and How to resolve the same.</p>
<p>If you have a website doing Country detection based on IP address then it may stop working if correct IP address is not available.</p>
<p>By default Varnish will remove several headers, this does not affect unless you have specific scenario.</p>
<p>I came across an issue where varnish was not sending Intermediary proxy IP or Public IP in a particular case.</p>
<p><span style="text-decoration: underline;"><strong>Scenario :</strong></span></p>
<ul>
<li>Some Hotel / Company has squid proxy configured and all traffic for Internet is routed via Squid.</li>
<li>User accessing my  website first hits the Load Balancer then Varnish &amp; then Apache</li>
<li>Apache is configured with mod_geoip. The code on my site does the Country redirection based on the IP address</li>
</ul>
<p><span style="text-decoration: underline;"><strong>Problem :</strong></span></p>
<ul>
<li>User (Behind that squid proxy) accessing my website follows this path :</li>
</ul>
<blockquote><p>Load Balancer -&gt; VARNISH -&gt; Apache</p></blockquote>
<p>Here apache gets only Internal IP (LAN IP of user) &amp; Load Balancer Internal IP as X-forwarded-for and Hence the IP based redirection FAILS!</p>
<p><span style="text-decoration: underline;"><strong>Solution :</strong></span></p>
<p>Credit goes to Mithrandir @ Varnish IRC Channel, Thanks!</p>
<p>Below mentioned changes were required to resolve the issue.</p>
<ul>
<li>At the start of the default.vcl add :</li>
</ul>
<blockquote>
<p style="text-align: left;"><strong>import std;</strong></p>
<p style="text-align: left;">
</blockquote>
<ul>
<li>Below     &#8220;<em>if (req.http.x-forwarded-for)</em>&#8221; add :</li>
</ul>
<blockquote><p><strong>std.collect(req.http.x-forwarded-for);</strong></p></blockquote>
<ul>
<li>Do varnish configtest &amp; reload. This should start showing the Public IP.</li>
</ul>
<div></div>
<ul>
<li>Below is the explanation from the documentation of <strong>vmod_std</strong> :</li>
</ul>
<blockquote><p>collect</p>
<p>Prototype<br />
collect(HEADER header)</p>
<p>Return value<br />
Void</p>
<p>Description<br />
Collapses the header, joining the headers into one.</p>
<p>Example<br />
std.collect(req.http.cookie); This will collapse several Cookie:<br />
headers into one, long cookie header.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://keyur.co.in/blog/varnish-x-forwarded-for-public-ip-not-visible/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
