<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Proxy on Danny Liu's Blog</title><link>https://dannypc1628.github.io/tags/proxy/</link><description>Recent content in Proxy on Danny Liu's Blog</description><generator>Hugo</generator><language>zh-TW</language><lastBuildDate>Mon, 14 Jan 2019 15:06:05 +0800</lastBuildDate><atom:link href="https://dannypc1628.github.io/tags/proxy/index.xml" rel="self" type="application/rss+xml"/><item><title>在CentOS 上用squid 建 reverse proxy 反向代理伺服器</title><link>https://dannypc1628.github.io/%E5%9C%A8centos-%E4%B8%8A%E7%94%A8squid-%E5%BB%BA-reverse-proxy-%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E4%BC%BA%E6%9C%8D%E5%99%A8/</link><pubDate>Mon, 14 Jan 2019 15:06:05 +0800</pubDate><guid>https://dannypc1628.github.io/%E5%9C%A8centos-%E4%B8%8A%E7%94%A8squid-%E5%BB%BA-reverse-proxy-%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E4%BC%BA%E6%9C%8D%E5%99%A8/</guid><description>&lt;p&gt;Linux上的proxy代理伺服器鳥哥是講squid，不過我看apache和Nginx也有proxy 模組 不過這次是講用squid當reverse proxy，把內部網站提供給外部瀏覽 例如內部網站www.danny.local(192.168.150.100)想給外部瀏覽，但為了安全性不能讓內部網站暴露在外 所以在外部架一台reverse proxy(192.168.123.187) 當替身(中間人)給外部瀏覽 先在DNS上設定要找www.danny.local這個網站的話去找替身192.168.123.187這台reverse proxy reverse proxy從設定檔中知道www.danny.local網站其實是在192.168.150.100上 由reverse proxy自己跟本尊192.168.150.100拿到www.danny.local資料後&lt;strong&gt;轉交&lt;/strong&gt;給外部瀏覽者 對外部使用者來說reverse proxy就是他要的www.danny.local 安裝squid這個代理伺服器軟體&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-brush:shell" data-lang="brush:shell"&gt; yum install squid
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;因為CentOS 7 上的squid已經提供最簡單的基本設定檔，只要改幾個值就能成為reverse proxy反向代理伺服器 首先到/etc/squid資料夾，編輯squid設定檔squid.conf&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-brush:shell" data-lang="brush:shell"&gt;vi /etc/squid/squid.conf
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;外部使用者要瀏覽網站都是找80port，所以我們要將設定檔中預設把監聽埠從3128改成80如下&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-brush:shell" data-lang="brush:shell"&gt;http_port 80 accel vhost vport
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;有些文章說prot 3130要關掉，但我看這份基本設定檔預設本來是關閉的 然後在設定檔最後面額外加入這幾段 加入本尊的ip地址192.168.150.100，名字叫dannywebsite 把本尊dannywebsite的資料，轉交給找www.danny.local的人&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-brush:shell" data-lang="brush:shell"&gt;#reverse proxy setting
cache_peer 192.168.150.100 parent 80 0 no-query originserver round-robin weight=1 name=dannywebsite
cache_peer_domain dannywebsite www.danny.local
cache_peer_access dannywebsite allow all
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;啟動squid&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-brush:shell" data-lang="brush:shell"&gt;/etc/init.d/squid start
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;完成&lt;/p&gt;</description></item></channel></rss>