【问题标题】:Empty reply from server with Varnish & hitch on separate cache server来自服务器的空回复,在单独的缓存服务器上使用清漆和挂接
【发布时间】:2022-01-12 23:08:48
【问题描述】:

在 ubuntu 20.04 服务器上安装清漆和挂接后,出现以下错误:

curl: (52) 来自服务器的空回复

我正在学习的教程:

[https://docs.varnish-software.com/tutorials/hitch-letsencrypt/][1]

就我而言,我有两台服务器 s1 和 s2 都安装了 ubuntu 20.04 服务器。 s1的本地静态ip:

192.168.1.105

s2的本地静态ip:

192.168.1.106

在 s1 上安装了 virtualmin 面板,并且一切正常。所以我 决定制作一个单独的缓存服务器并安装清漆和挂钩:

sudo apt install varnish -y 

sudo apt install hitch -y

default.vcl 文件的变化:

    backend default {
    .host = "192.168.1.105";
    .port = "80";

   }

hitch.conf:

# Run 'man hitch.conf' for a description of all options.
    frontend = {
        host = "*"
        port = "443"
    }
    backend = "[127.0.0.1]:8443"    # 6086 is the default Varnish PROXY port.
#workers = 4                     # number of CPU cores

#daemon = on

# We strongly recommend you create a separate non-privileged hitch
# user and group
#user = "hitch"
#group = "hitch"

# Enable to let clients negotiate HTTP/2 with ALPN. (default off)
# alpn-protos = "h2, http/1.1"

# run Varnish as backend over PROXY; varnishd -a :80 -a localhost:6086,PROXY ..
#write-proxy-v2 = on             # Write PROXY header

#pem files

    pem-file = "/etc/letsencrypt/live/example.com/hitch-bundle.pem"

unit file:

    [Unit]
Description=Varnish HTTP accelerator
Documentation=https://www.varnish-cache.org/docs/6.1/ man:varnishd

    [Service]
    Type=simple
    LimitNOFILE=131072
    LimitMEMLOCK=infinity
    ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -a localhost:8443,proxy -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,3G
    ExecReload=/usr/share/varnish/varnishreload
    ProtectSystem=full
    ProtectHome=true
    PrivateTmp=true
    PrivateDevices=true

    [Install]
    WantedBy=multi-user.target

注意:我对网络一无所知,所以主路由器连接第二路由器,s1和s2都直接连接第二路由器。 dmz 主机 ip 也从 s1 ip 更改为 s2 ip。

结果:

curl -i https://example.com
curl: (52) Empty reply from server.

根据这个命令 varnishlog -g request -q "ReqUrl eq '/'" VSM:无法获取 varnishd,它正在运行吗?

请指导谢谢。

【问题讨论】:

    标签: ubuntu networking server varnish virtualmin


    【解决方案1】:

    通过启用 PROXY 协议修复空回复

    在您的hitch.conf 中取消注释以下行:

    #write-proxy-v2 = on
    

    这将允许使用 PROXY 协议与 Varnish 进行通信。此协议通过 TLV 属性将有关原始客户端 (与 Hitch 连接的客户端) 的更多信息传递给 Varnish。

    您正在从 Hitch 连接到端口 8443,这是 Varnish 的 PROXY 协议端口,如以下 varnishd 运行时参数所述:

    -a localhost:8443,proxy
    

    现在 Varnish 期望代理信息存在于 TCP 数据包中,但找不到该信息。因此是空的回复。

    让 Varnish 协议感知

    如果您的应用程序强制 HTTPS 重定向,重要的是让 Varnish 了解所使用的协议。它可以是 HTTP 或 HTTPS。

    如果您通过 PROXY 协议使用 Hitch,我们可以使用 vmod_proxy 来识别这些连接并创建适当的缓存变体。

    这是 VCL 代码:

    vcl 4.1;
    
    import proxy;
    
    sub vcl_recv {
        if (proxy.is_ssl()) {
            set req.http.X-Forwarded-Proto = "https";
        } else {
            set req.http.X-Forwarded-Proto = "http";
        }
    }
    
    sub vcl_backend_response {
        if(beresp.http.Vary) {
            if(beresp.http.Vary !~ "X-Forwarded-Proto") {
                set beresp.http.Vary = set beresp.http.Vary + ", X-Forwarded-Proto";
            }
        } else {
            set beresp.http.Vary = "X-Forwarded-Proto";
        }
    }
    

    此代码将存储每个响应的 HTTP 版本和 HTTPS 版本。

    奖励:启用 HTTP/2

    当您使用它时,您还可以通过取消注释 hitch.conf 文件中的以下行来启用 HTTP/2:

    # alpn-protos = "h2, http/1.1"
    

    为确保在 Varnish 中启用 HTTP/2,请在您的 systemd 配置中将以下运行时参数添加到 varnishd

    -p feature=+http2
    

    重新启动 Hitch & Varnish 和 Hitch 将能够终止 HTTP/2 请求的 TLS。

    【讨论】:

    • 感谢您的回答,我再次根据您的建议清理安装 ubuntu 和最新的清漆和挂接,现在错误是:
    • curl -i example.com HTTP/1.1 302 发现日期:2022 年 1 月 11 日星期二 18:32:12 GMT 服务器:Apache 位置:example.com 内容长度:214 内容类型:文本/html; charset=iso-8859-1 X-Varnish: 98348 Age: 0 Via: 1.1 varnish (Varnish/7.0) Connection: keep-alive 302 Found

      Found

      文档已移至此处 a>.

    猜你喜欢
    • 2017-04-26
    • 2015-02-28
    • 2018-08-13
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 2015-07-16
    • 1970-01-01
    相关资源
    最近更新 更多