如何配置squid作為docker映像的虛擬主機

如何配置squid作為docker映像的虛擬主機

我有一台運行一堆 docker 映像的伺服器(基本上只是託管一堆網站)

它們都有不同的域名,都指向伺服器的IP

(假設伺服器IP是111.222.333.444)

(我的網域是 www.one.com、www.two.com、www. Three.com)

目前,docker 映像將連接埠 80 全部匯出到不同連接埠上的伺服器:

  • www.one.com 埠為 5080
  • www.two.com 埠為 5180
  • www.two.com 埠為 5280

因此,如果我造訪 URL:port,則會顯示網站。

但我想使用虛擬主機,這樣我就可以存取每個 URL 上的連接埠 80,並且它只是重定向到相關連接埠。

我知道如何用 apache 來做到這一點,並且可能可以用 nginx 來解決。

但我聽說這就是魷魚的真正用途(加上apache作為虛擬主機似乎非常重)

我已經在我的ubuntu12.04伺服器上安裝了squid3

這是到目前為止我的squid.conf

http_port 80 accel defaultsite=www.one.com no-vhost
cache_peer 127.0.0.1 parent 5080 0 no-query originserver name=YourAccelNameHere
acl your_site_acl dstdomain www.one.com
http_access allow your_site_acl
cache_peer_access YourAccelNameHere allow your_site_acl
cache_peer_access YourAccelNameHere deny all

從閱讀「應該」將 www.one.com 轉送到本機上的連接埠 5080 的教學(但事實並非如此)

我真的對魷魚一無所知,而且從我所有的谷歌搜尋中,我似乎找不到一個簡單的教程來完成我想要的事情。

誰能給我指點一個好的教程,或更好地提供我一個可以完成我所追求的任務的squid.conf?

謝謝

答案1

我自己回答過

我的解決方案是:

我用清漆解決了

apt-get install varnish

然後我設定了我的

/etc/default/varnish

START=yes
NFILES=131072
MEMLOCK=82000
DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

然後設定我的

/etc/varnish/default.vcl

backend default {
    .host = "127.0.0.1";
    .port = "80";
}

backend one_website {
    .host = "127.0.0.1";
    .port = "5080";
}

backend two_website {
    .host = "127.0.0.1";
    .port = "5180";
}

## Multiple virtual host
sub vcl_recv {
 if (req.http.host ~ "^www.default.com(:[0-9]+)?$") {
    set req.backend = default;
 } else if (req.http.host ~ "^www.one.com(:[0-9]+)?$") {
    set req.backend = one_website;
 } else if (req.http.host ~ "^www.two.com(:[0-9]+)?$") {
    set req.backend = two_website;
 }
}

## Fetch
sub vcl_fetch {
        ## Remove the X-Forwarded-For header if it exists.
        remove req.http.X-Forwarded-For;

        ## insert the client IP address as X-Forwarded-For. This is the normal IP address of the user.
        set    req.http.X-Forwarded-For = req.http.rlnclientipaddr;
        ## Added security, the "w00tw00t" attacks are pretty annoying so lets block it before it reaches our webserver
        if (req.url ~ "^/w00tw00t") {
                error 403 "Not permitted";
        }
                ## Deliver the content
        return(deliver);
}

## Deliver
sub vcl_deliver {
        ## We'll be hiding some headers added by Varnish. We want to make sure people are not seeing we're using Varnish.
        ## Since we're not caching (yet), why bother telling people we use it?
        remove resp.http.X-Varnish;
        remove resp.http.Via;
        remove resp.http.Age;

        ## We'd like to hide the X-Powered-By headers. Nobody has to know we can run PHP and have version xyz of it.
        remove resp.http.X-Powered-By;
}

我希望這可以幫助其他面臨這個問題的人!

相關內容