<?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>限制存取 &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/%E9%99%90%E5%88%B6%E5%AD%98%E5%8F%96/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Sat, 07 Nov 2020 15:17:40 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>限制存取 &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Solr 教學 (3) &#8211; 以 Remote Address Filter 限制存取</title>
		<link>https://noter.tw/3094/solr-%e6%95%99%e5%ad%b8-3-%e4%bb%a5-remote-address-filter-%e9%99%90%e5%88%b6%e5%ad%98%e5%8f%96/</link>
					<comments>https://noter.tw/3094/solr-%e6%95%99%e5%ad%b8-3-%e4%bb%a5-remote-address-filter-%e9%99%90%e5%88%b6%e5%ad%98%e5%8f%96/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Mon, 14 Oct 2013 15:32:54 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[solr.xml]]></category>
		<category><![CDATA[Catalina]]></category>
		<category><![CDATA[container]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[Remote Address Filter]]></category>
		<category><![CDATA[限制存取]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[cloudflare]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[web.xml]]></category>
		<category><![CDATA[solr]]></category>
		<guid isPermaLink="false">http://wazai.net/?p=3094</guid>

					<description><![CDATA[<p>前面&#160;Solr 教學 (1) – 安裝篇、Solr 教學 (2) – tomcat 7 以帳號密碼限制存取頁面 講解了 Solr 安裝方式以及頁面安全性設定，這篇文章要記錄透過 tomcat&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3094/solr-%e6%95%99%e5%ad%b8-3-%e4%bb%a5-remote-address-filter-%e9%99%90%e5%88%b6%e5%ad%98%e5%8f%96/" data-wpel-link="internal">Solr 教學 (3) &#8211; 以 Remote Address Filter 限制存取</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[<p>前面&nbsp;<a href="https://noter.tw/3084/solr-%e6%95%99%e5%ad%b8-1-%e5%ae%89%e8%a3%9d%e7%af%87/" target="_blank" rel="noopener noreferrer" data-wpel-link="internal">Solr 教學 (1) – 安裝篇</a>、<a href="https://noter.tw/3082/solr-%e6%95%99%e5%ad%b8-2-tomcat-7-%e4%bb%a5%e5%b8%b3%e8%99%9f%e5%af%86%e7%a2%bc%e9%99%90%e5%88%b6%e5%ad%98%e5%8f%96%e9%a0%81%e9%9d%a2/" target="_blank" rel="noopener noreferrer" data-wpel-link="internal">Solr 教學 (2) – tomcat 7 以帳號密碼限制存取頁面</a> 講解了 Solr 安裝方式以及頁面安全性設定，這篇文章要記錄透過 tomcat 7 內建的 Remote Address Filter 來設定允許連線 IP 的白名單。<br><span id="more-3094"></span>這個方法非常簡單，不過要注意的是 tomcat 版本不同會有不同的設定方法，這邊小蛙的環境是 Ubuntu 13.04 64bit + Solr 4.5.0 + tomcat 7，以下的方法僅適用於 tomcat 7 這個版本！</p>
<p>在測試這個功能的時候發生一個小插曲，以往設定完馬上就可以用了，這次測試時不管怎麼做都會出現 403 Forbidden 的錯誤，簡直是晴天霹靂，完全摸不著頭緒，已經設定好小蛙自己使用的 IP，還是一樣 403，最扯的是 127.0.0.1 本機測試也還是一樣的情況，在資訊這行經常會遇到靈異現象，可能要買一包綠色乖乖才可以，不過 VPS 主機在美國要怎麼辦呢 &#8230;</p>
<p>後來 &#8230; 突然想到一件事情，小蛙的網站有使用 <a href="https://www.cloudflare.com/" target="_blank" rel="noopener noreferrer nofollow external" data-wpel-link="external" class="wpel-icon-right">CloudFlare<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 這個服務來加快網頁速度，CloudFlare 會根據使用者的設定，比如原本的 http://wazai.net/ 假設連結到小蛙的 IP (1.2.3.4)，這個 1.2.3.4 的 IP 是在美國紐約，現在有一個日本來的使用者連結了 http://wazai.net，此刻 CloudFlare 發現日本這邊也有一個 CloudFlare 伺服器，就會將日本的使用者連結到日本的 CloudFlare 伺服器以加快網站速度。</p>
<p>就在這個 moment，真正連到小蛙伺服器的 IP 就變成 CloudFlare 日本伺服器的 IP，而不是真正日本使用者的 IP，當然這邊 CloudFlare 也有提供自訂的 Header 可以取得原始日本使用者的 IP。</p>
<p>到這邊大概懂了 &#8230; 竟然被那麼奇怪的問題卡了那麼久 &#8230; 就是小蛙在測試的時候，也是連結 http://domain:8080/solr ，但真正收到的 IP 卻不是小蛙自己本身的 IP，而是接近小蛙位置的 CloudFlare Server IP，就連在本機 127.0.0.1 的時候也是一樣的狀況 &#8230; CloudFlare 為了避免這個問題，可以在網站上設定可以直接連接的 Domain，例如：domain 透過 CloudFlare，額外新增設定 nocf.domain 來避免使用 CloudFlare。</p>
<p>上教學！有兩種設定方式，一種是 <a href="http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Remote_Address_Filter" target="_blank" rel="noopener noreferrer nofollow external" data-wpel-link="external" class="wpel-icon-right">Apache Tomcat 官網範例<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 提到的透過 web.xml 設定 &lt;filter&gt;，第二種是直接在 &lt;Host&gt; &lt;Context&gt; 等 Catalina Container 中設定。</p>
<h4>透過 &lt;filter&gt;</h4>
<ol>
<li>&lt;filter&gt; 過濾器在每個專案下的 web.xml 中設定，在 &lt;web-app&gt; &lt;/web-app&gt; 之間加入 &lt;filter&gt; 設定，IP 的部分設定為 1.2.3.4 改寫成 1\.2\.3\.4，IP 與 IP 之間以「|」分隔。
<div>
<div id="highlighter_286384" class="syntaxhighlighter  bash">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gutter">
<div class="line number1 index0 alt2">1</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="bash comments"># vim /var/lib/tomcat7/webapps/solr/WEB-INF/web.xml</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<div id="highlighter_245018" class="syntaxhighlighter  xml">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gutter">
<div class="line number1 index0 alt2">01</div>
<div class="line number2 index1 alt1">02</div>
<div class="line number3 index2 alt2">03</div>
<div class="line number4 index3 alt1">04</div>
<div class="line number5 index4 alt2">05</div>
<div class="line number6 index5 alt1">06</div>
<div class="line number7 index6 alt2">07</div>
<div class="line number8 index7 alt1">08</div>
<div class="line number9 index8 alt2">09</div>
<div class="line number10 index9 alt1">10</div>
<div class="line number11 index10 alt2">11</div>
<div class="line number12 index11 alt1">12</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">filter</code><code class="xml plain">&gt;</code></div>
<div class="line number2 index1 alt1"><code class="xml spaces">&nbsp;&nbsp;</code><code class="xml plain">&lt;</code><code class="xml keyword">filter-name</code><code class="xml plain">&gt;Remote Address Filter&lt;/</code><code class="xml keyword">filter-name</code><code class="xml plain">&gt;</code></div>
<div class="line number3 index2 alt2"><code class="xml spaces">&nbsp;&nbsp;</code><code class="xml plain">&lt;</code><code class="xml keyword">filter-class</code><code class="xml plain">&gt;org.apache.catalina.filters.RemoteAddrFilter&lt;/</code><code class="xml keyword">filter-class</code><code class="xml plain">&gt;</code></div>
<div class="line number4 index3 alt1"><code class="xml spaces">&nbsp;&nbsp;</code><code class="xml plain">&lt;</code><code class="xml keyword">init-param</code><code class="xml plain">&gt;</code></div>
<div class="line number5 index4 alt2"><code class="xml spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="xml plain">&lt;</code><code class="xml keyword">param-name</code><code class="xml plain">&gt;allow&lt;/</code><code class="xml keyword">param-name</code><code class="xml plain">&gt;</code></div>
<div class="line number6 index5 alt1"><code class="xml spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="xml plain">&lt;</code><code class="xml keyword">param-value</code><code class="xml plain">&gt;127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1&lt;/</code><code class="xml keyword">param-value</code><code class="xml plain">&gt;</code></div>
<div class="line number7 index6 alt2"><code class="xml spaces">&nbsp;&nbsp;</code><code class="xml plain">&lt;/</code><code class="xml keyword">init-param</code><code class="xml plain">&gt;</code></div>
<div class="line number8 index7 alt1"><code class="xml plain">&lt;/</code><code class="xml keyword">filter</code><code class="xml plain">&gt;</code></div>
<div class="line number9 index8 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">filter-mapping</code><code class="xml plain">&gt;</code></div>
<div class="line number10 index9 alt1"><code class="xml spaces">&nbsp;&nbsp;</code><code class="xml plain">&lt;</code><code class="xml keyword">filter-name</code><code class="xml plain">&gt;Remote Address Filter&lt;/</code><code class="xml keyword">filter-name</code><code class="xml plain">&gt;</code></div>
<div class="line number11 index10 alt2"><code class="xml spaces">&nbsp;&nbsp;</code><code class="xml plain">&lt;</code><code class="xml keyword">url-pattern</code><code class="xml plain">&gt;/*&lt;/</code><code class="xml keyword">url-pattern</code><code class="xml plain">&gt;</code></div>
<div class="line number12 index11 alt1"><code class="xml plain">&lt;/</code><code class="xml keyword">filter-mapping</code><code class="xml plain">&gt;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</li>
<li>設定完成！重新啟動 tomcat。</li>
</ol>
<h4>&nbsp;</h4>
<h4>透過 &lt;Context&gt;</h4>
<ol>
<li>進入到 solr 個別設定檔，在 &lt;Context&gt; &lt;/Context&gt; 之間加入 &lt;Value /&gt;
<div>
<div id="highlighter_646750" class="syntaxhighlighter  bash">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gutter">
<div class="line number1 index0 alt2">1</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="bash comments"># vim /var/lib/tomcat7/conf/Catalina/localhost/solr.xml</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<div id="highlighter_936594" class="syntaxhighlighter  xml">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gutter">
<div class="line number1 index0 alt2">1</div>
<div class="line number2 index1 alt1">2</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">Valve</code> <code class="xml color1">className</code><code class="xml plain">=</code><code class="xml string">"org.apache.catalina.valves.RemoteAddrValve"</code></div>
<div class="line number2 index1 alt1"><code class="xml spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="xml color1">allow</code><code class="xml plain">=</code><code class="xml string">"127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"</code><code class="xml plain">/&gt;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</li>
<li>IP 設定規則同 &lt;filter&gt; 第一點。</li>
<li>設定完成！重新啟動 tomcat。</li>
</ol>


<p><strong>Solr 系列文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/3084/solr-%e6%95%99%e5%ad%b8-1-%e5%ae%89%e8%a3%9d%e7%af%87/" data-wpel-link="internal">Solr 教學 (1) &#8211; 安裝篇</a></li><li><a href="https://noter.tw/3082/solr-%e6%95%99%e5%ad%b8-2-tomcat-7-%e4%bb%a5%e5%b8%b3%e8%99%9f%e5%af%86%e7%a2%bc%e9%99%90%e5%88%b6%e5%ad%98%e5%8f%96%e9%a0%81%e9%9d%a2/" data-wpel-link="internal">Solr 教學 (2) – tomcat 7 以帳號密碼限制存取頁面</a></li><li><a href="https://noter.tw/3094/solr-%e6%95%99%e5%ad%b8-3-%e4%bb%a5-remote-address-filter-%e9%99%90%e5%88%b6%e5%ad%98%e5%8f%96/" data-wpel-link="internal">Solr 教學 (3) – 以 Remote Address Filter 限制存取</a></li><li><a href="https://noter.tw/3160/solr-%e6%95%99%e5%ad%b8-4-%e4%bd%bf%e7%94%a8-dataimport-%e5%8c%af%e5%85%a5%e8%b3%87%e6%96%99%e5%ba%ab%e8%b3%87%e6%96%99/" data-wpel-link="internal">Solr 教學 (4) – 使用 DataImport 匯入資料庫資料</a></li><li><a href="https://noter.tw/3170/solr-%e6%95%99%e5%ad%b8-5-%e5%bb%ba%e7%ab%8b%e6%96%b0%e7%9a%84-core/" data-wpel-link="internal">Solr 教學 (5) – 建立新的 Core</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3094/solr-%e6%95%99%e5%ad%b8-3-%e4%bb%a5-remote-address-filter-%e9%99%90%e5%88%b6%e5%ad%98%e5%8f%96/" data-wpel-link="internal">Solr 教學 (3) &#8211; 以 Remote Address Filter 限制存取</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/3094/solr-%e6%95%99%e5%ad%b8-3-%e4%bb%a5-remote-address-filter-%e9%99%90%e5%88%b6%e5%ad%98%e5%8f%96/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
