Varnish作為Apache2伺服器的反向代理,連接埠重定向問題

Varnish作為Apache2伺服器的反向代理,連接埠重定向問題

我一直在尋找,有很多人有同樣的問題,但沒有明確的解決方案(或至少我沒有找到)。

我使用 Varnish-Cache (3.0) 作為在連接埠 80 中偵聽的反向代理,以便 Apache 2 Web 伺服器在連接埠 88 中偵聽。

如果我請求以下 URL,它工作正常:http://伺服器/東西/

但是,如果我要求這樣做:http://伺服器/東西(最後不帶“/”),瀏覽器被重定向到後端Apache的連接埠(http://伺服器:88/stuff/)。

在這種情況下我該如何設定 Apache 2 的行為?

先致謝!

答案1

檢查 httpd.conf 上的 UseCanonicalName 指令

#
# UseCanonicalName: Determines how Apache constructs self-referencing
# URLs and the SERVER_NAME and SERVER_PORT variables.
# When set "Off", Apache will use the Hostname and Port supplied
# by the client.  When set "On", Apache will use the value of the
# ServerName directive.
#
UseCanonicalName Off

您也可以將其去除在清漆上,請嘗試以下操作:

sub vcl_fetch { 
   if (beresp.status == 301 || beresp.status == 302) 
   { 
      set beresp.http.Location = regsub(beresp.http.Location, "^(\w+://[^/]+):\d+", "\1"); 
   } 
} 

相關內容