%E8%AB%8B%E6%B1%82.png)
我在 Proxmox 中安裝了 5 個 LXC 容器。每個容器都有一個在內部啟動並運行的 Apache2 Web 伺服器,指向一個註冊的網域。
所以:
container1指向example1.com並且有一個本地IP位址192.168.2.225
容器2指向example2.com並且有一個本地IP位址192.168.2.230
容器3指向example3.com並且有一個本地IP位址192.168.2.235
等等。
我想將對 5 個不同網域的請求轉送到對應的容器。所有容器都有靜態 IP,並在 vmbr0 上橋接到實體網路卡 (enp3s0)
所以我嘗試用一個單獨的容器來實現它,運行魷魚代理,本地 IP 位址為192.168.2.253和港口3128,這是Squid的預設監聽埠。
首先,我在 Proxmox 主機上設定了 iptables,規則如下:
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 22 -j DNAT --to 192.168.2.253:3128
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 192.168.2.253:3128
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 443 -j DNAT --to 192.168.2.253:3128
iptables --t nat -A POSTROUTING --out-interface vmbr0 -j MASQUERADE
之後我嘗試配置 Squid:
http_port 3128
http_access allow all
http_port 3128 intercept
visible_hostname squid.proxy
acl 100 dstdomain .example1.com
acl 101 dstdomain .example2.com
acl 102 dstdomain .example3.com
cache_peer 192.168.2.225 parent 80 0 no-query
cache_peer 192.168.2.230 parent 80 0 no-query
cache_peer 192.168.2.235 parent 80 0 no-query
當瀏覽到 example1.com 時,Squid 通知我以下訊息:
The requested URL could not be retrieved
我的問題是:我該怎麼做才能將每個網域成功轉發到其對應的容器?