如何讓 Apache 和 Nginx 同時支援 Varnish?

如何讓 Apache 和 Nginx 同時支援 Varnish?

我有一個設置,我讓Varnish 在連接埠8080 上的Apache 後面的連接埠80 上監聽,而我打算在8081 上使用Nginx。託管的網站之一,而且由於 Varnish 已經在 80 上,所以我不能在同一連接埠上使用 Nginx。

我不想完全擺脫 Apache,因為我仍然需要它來存取我的 vps 控制面板,聖托拉準確地說 Apache 位於 8080 上的位置。這裡,OP 希望在 Apache 的不同 IP 上擁有兩個不同的網域,所以它並沒有真正的幫助。

另外,我在某處讀到了有關server.port在 vcl 中使用該指令的信息,但我不知道如何做。這是我的一部分的樣子default.vcl

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

PS:我還沒安裝Nginx。

答案1

在這裡,您想要在 Varnish 中設定額外的後端,並將一些請求路由到它。

首先為 Nginx 新增一個新的後端:

backend nginx {
    .host = "127.0.0.1";
    .port = "8081";
}

然後您可以將一些請求路由到它。這通常在vcl_recv子例程中完成。例如,如果透過網域存取Sentora sentora.example.org

sub vcl_recv {
    if (req.http.host ~ "(?i)^sentora.example.org$") {
        # Route requests to sentora.example.org to the old Apache backend.
        set req.backend = default;
    } else {
        # Everything else to nginx.
        set req.backend = nginx;
    }
}

進階後端配置了解更多範例。文中也有很多例子Varnish 配置語言文件.

相關內容