指定清漆的默认虚拟主机

我在Scientific Linux 6.4(64bit)上使用Varnish-3.0.5:

$ rpm -q varnish varnish-3.0.5-1.el5.centos.x86_64 $ cat /etc/redhat-release Scientific Linux release 6.4 (Carbon) $ uname -a Linux XXX.XXX.XXX 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 11:13:47 CDT 2013 x86_64 x86_64 x86_64 GNU/Linux $ curl XXX.XX.XX.XXX <html> <head> <title>Page Unavailable</title> <style> body { background: #303030; text-align: center; color: white; } #page { border: 1px solid #CCC; width: 500px; margin: 100px auto 0; padding: 30px; background: #323232; } a, a:link, a:visited { color: #CCC; } .error { color: #222; } </style> </head> <body onload="setTimeout(function() { window.location = '/' }, 5000)"> <div id="page"> <h1 class="title">Page Unavailable</h1> <p>The page you requested is temporarily unavailable.</p> <p>We're redirecting you to the <a href="/">homepage</a> in 5 seconds.</p> <div class="error">(Error 503 Service Unavailable)</div> </div> </body> </html> $ 

我试图弄清楚如何configuration默认的虚拟主机,因为我得到Error 503 Service Unavailable如果至less有一个我的后端(S)是closures,每当我运行curl IP地址。 我是否需要在req.http.host指定IP地址以及在vcl_recv()内部以便让我停止获取503? 或者我怎么指定哪个虚拟主机是默认的?

所有的拳头都让我说,在没有看到你实际的VCLconfiguration的情况下给出build议是相当困难的。

回答你的实际问题

你可以在你的vcl_recv开头设置一个默认的主机,注意你的后端应该被configuration为响应那个确切的主机

 sub vcl_recv { /* set a default host if no host is provided on the request or if it is empty */ if ( ! req.http.host || req.http.host == "") { set req.http.host = "your.default.host.tld"; } # ... } 

我认为你不必乱搞IP和req.http.host ,你最好使用curl来传递一个主机头清漆(如curl -H "Host: your.default.host.tld" http://XX.XX.XX.XXX/


关于该主题的一些一般性build议:

将错误的控制逻辑添加到您的VCL [1]

你是否正确设置后端?

请记住,清漆将使用“默认”后端(或导演),除非指示在您的VCI逻辑上使用其他

添加健康探测器并查看后端失败

使用一致的健康探测器[2]并使用命令行命令varnishadm debug.health查看文档以获得更好的理解[3]

添加一个重启逻辑到你的vlc错误

像这样的东西

 sub vcl_error { # ... /* Try to restart request in case of failure */ if (obj.status == 503 && req.restarts < 5) { set obj.http.X-Restarts = req.restarts; return(restart); } # Before any deliver return (deliver); } 

将debugging逻辑添加到您的vlc错误综合响应

请记住,您可以在vcl_fetch上添加debugging标头,将后端错误代码传递给您的varnish错误响应:

 sub vcl_fetch { # ... set beresp.http.X-Debug-Backend-Code = beresp.status; # ... } sub vcl_error { # ... synthetic {"" # Insert the following at the end of your current response <p>Backend Status code was "} + obj.http.X-Debug-Backend-Code + {"</p> </body> </html> "}; # ... return (deliver); } 

[1] https://www.varnish-cache.org/docs/3.0/tutorial/handling_misbehaving_servers.html

[2] https://www.varnish-cache.org/docs/3.0/reference/vcl.html#backend-probes

[3] https://www.varnish-cache.org/trac/wiki/BackendPolling#CLI命&#x4EE4;