Varnish host_header不会发送到后端

标签 varnish varnish-4

我试图用需要精确主机名的两个后端运行 Varnish 。但是我的nginx收到了本地主机主机头。

这是我的配置:

probe healthcheck {
    .url = "/";
    .interval = 5s;
    .timeout = 15s;
    .window = 5;
    .threshold = 3;
}

# Define the list of backends (web servers).
# Port 443 Backend Servers for SSL
backend bimer1 {
    .host = "nginx-proxy";
    .host_header = "site1.example.com.br";
    .port = "80";
    .probe = healthcheck;
}

backend bimer2 {
    .host = "nginx-proxy";
    .host_header = "site2.example.com.br";
    .port = "80";
    .probe = healthcheck;
}

这是我的Nginx访问日志:

bimer-cache-nginx-ssl-proxy_1 | 172.17.0.3--[21/Jun/2017:13:41:47 +0000]“POST/ws/Servicos/Geral/Localizacoes.svc/REST/LocalizarPessoas HTTP/1.1” 502575“-”“Mozilla/5.0( X11; Linux x86_64)AppleWebKit/537.36(KHTML,例如Gecko)Chrome/59.0.3071.104 Safari/537.36“<-> localhost 172.17.0.1,172.17.0.3

似乎将host_header参数设置为backend不适用于常规请求。但是健康检查运行良好。

最佳答案

Varnish是透明的HTTP代理。它将客户端(您的浏览器)发送给它的所有Host header 转发到后端。因此,如果您通过http://localhost/访问它,那么localhost是您的后端将在Host header 中看到的内容。

此外,您绝不应该在Varnish后端定义中使用DNS名称。它应该看起来像这样:

backend bimer1 {
    .host = "1.2.3.4";
    # ... etc.

目前,您配置的后端解析为相同的机器nginx-proxy。另外,access.log的结果也不来自运行状况检查。 (您配置的运行状况检查将显示为对根URL/的访问权限)

也许您误解了Varnish配置。如果您的计划是通过同一台计算机来服务多个网站,那么您应该只使用一个后端。多个后端适用于多台计算机。

关于 Varnish host_header不会发送到后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44677939/

相关文章:

Tomcat 的 server.xml 宿主容器和 Varnish

ubuntu - Varnish digitalocean 配置指南 : Symbol not found: 'req.backend.healthy' (expected type BOOL): 后出错

symfony - S3 Bucket Policy by domain 返回 403 Forbidden for object requests in Symfony app with Varnish

Varnish 列出缓存中的所有 URL

apache - 如何使用多个apache虚拟主机设置varnish 4.1.2?

angular - 在Varnish代理后面的Angular 5.6.0中设置文档根目录

heroku - Heroku雪松堆栈中的机架缓存与Varnish的缺点?

根据状态代码清空缓存项目

kubernetes - 在kubernetes部署中配置Varnish后端

varnish4 与 varnish3 - 优雅行为