<?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>X-Forwarded-For | SDT 攻城獅區</title>
	<atom:link href="https://sdt.hameba.tw/tag/x-forwarded-for/feed/" rel="self" type="application/rss+xml" />
	<link>https://sdt.hameba.tw</link>
	<description>由Steven, Der, Ted 三位高級打字員所組成，是三位工程師(攻城獅)所維護的技術分享平台，或許偶爾會分享一些日常，有任何問題或是錯誤的部分，歡迎留言告訴我們！</description>
	<lastBuildDate>Sun, 08 Dec 2019 04:41:37 +0800</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.3</generator>

<image>
	<url>https://sdt.hameba.tw/wp-content/uploads/2020/02/hameba_favicon-150x150.png</url>
	<title>X-Forwarded-For | SDT 攻城獅區</title>
	<link>https://sdt.hameba.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Java經過ProxyPass獲取正確客戶端真實IP方法</title>
		<link>https://sdt.hameba.tw/287/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java%25e7%25b6%2593%25e9%2581%258eproxypass%25e7%258d%25b2%25e5%258f%2596%25e6%25ad%25a3%25e7%25a2%25ba%25e5%25ae%25a2%25e6%2588%25b6%25e7%25ab%25af%25e7%259c%259f%25e5%25af%25a6ip%25e6%2596%25b9%25e6%25b3%2595</link>
				<comments>https://sdt.hameba.tw/287/#respond</comments>
				<pubDate>Sun, 08 Dec 2019 04:38:53 +0000</pubDate>
		<dc:creator><![CDATA[Hsu Steven]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[getRemoteAddr]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ProxyPass]]></category>
		<category><![CDATA[X-Forwarded-For]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=287</guid>
				<description><![CDATA[<p>通常做好AP Server後，會有一台Web Server做Proxypass代理減少附載平衡 但是通常經過一 &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/287/" class="more-link">閱讀全文<span class="screen-reader-text">〈Java經過ProxyPass獲取正確客戶端真實IP方法〉</span></a></p>
The post <a href="https://sdt.hameba.tw/287/">Java經過ProxyPass獲取正確客戶端真實IP方法</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>通常做好AP Server後，會有一台Web Server做Proxypass代理減少附載平衡</p>
<p>但是通常經過一層之後，request header也就會有改變，</p>
<p><span id="more-287"></span></p>
<p>造成AP得到的getRemoteAddr都是Web Server的ip</p>
<p>所以Java攔截器層可以增加以下方式來記錄真實Client IP</p><pre class="crayon-plain-tag">public static String getIpAddress(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    if (ip.contains(",")) {
        return ip.split(",")[0];
    } else {
        return ip;
    }
}</pre><p><strong>Request Header參數說明</strong></p>
<ul>
<li>X-Forwarded-For</li>
</ul>
<p>這是一個 Squid 開發的字段，只有在通過了HTTP代理或者負載均衡服務器時才會添加該項。</p>
<p>格式為X-Forwarded-For:client1,proxy1,proxy2，一般情況下，第一個ip為客戶端真實ip，後面的為經過的代理服務器ip。現在大部分的代理都會加上這個請求頭。</p>
<ul>
<li>Proxy-Client-IP/WL- Proxy-Client-IP</li>
</ul>
<p>這個一般是經過apache http服務器的請求才會有，用apache http做代理時一般會加上Proxy-Client-IP請求頭，而WL-Proxy-Client-IP是他的weblogic插件加上的頭。</p>
<ul>
<li>HTTP_CLIENT_IP</li>
</ul>
<p>有些代理服務器會加上此請求頭。</p>
<ul>
<li>X-Real-IP<br />
nginx代理一般會加上此請求頭。</li>
</ul>
<p>Reference</p>
<p><a href="https://www.itread01.com/content/1532062937.html">https://www.itread01.com/content/1532062937.html</a></p>
<div id="gtx-trans">
<div class="gtx-trans-icon"></div>
</div>The post <a href="https://sdt.hameba.tw/287/">Java經過ProxyPass獲取正確客戶端真實IP方法</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/287/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
	</channel>
</rss>
