apache 清漆:400不良要求/仅

yftpprvb  于 2023-02-24  发布在  Apache
关注(0)|答案(1)|浏览(152)

我的varnish服务器仅对发往站点/https://example.com/)的请求超时,而所有其他请求均正常处理。例如:(示例网站)
清漆日志的输出为:

*   << Request  >> 164200    
-   Begin          req 164199 rxreq
-   Timestamp      Start: 1676987476.561832 0.000000 0.000000
-   Timestamp      Req: 1676987476.561832 0.000000 0.000000
-   ReqStart       127.0.0.1 36702 a0
-   ReqMethod      GET
-   ReqURL         /
-   ReqProtocol    HTTP/1.0
-   ReqHeader      X-Real-IP: 10.254.27.52
-   ReqHeader      X-Forwarded-For: 10.254.27.52
-   ReqHeader      X-Forwarded-Proto: https
-   ReqHeader      X-Forwarded-Port: 443
-   ReqHeader      Connection: close
-   ReqUnset       X-Forwarded-For: 10.254.27.52
-   ReqHeader      X-Forwarded-For: 10.254.27.52, 127.0.0.1
-   VCL_call       RECV
-   ReqHeader      Surrogate-Capability: Varnish=ESI/1.0
-   ReqHeader      Host: 
-   ReqURL         /
-   VCL_return     hash
-   VCL_call       HASH
-   VCL_return     lookup
-   Hit            3 2414.934756 120.000000 0.000000
-   VCL_call       HIT
-   VCL_return     deliver
-   RespProtocol   HTTP/1.1
-   RespStatus     400
-   RespReason     Bad Request
-   RespHeader     Date: Tue, 21 Feb 2023 13:31:31 GMT
-   RespHeader     Server: Apache
-   RespHeader     Content-Length: 226
-   RespHeader     Content-Type: text/html; charset=iso-8859-1
-   RespHeader     x-url: /
-   RespHeader     x-host: 
-   RespHeader     X-Varnish: 164200 3
-   RespHeader     Age: 1185
-   RespHeader     Via: 1.1 varnish (Varnish/6.0)
-   VCL_call       DELIVER
-   RespUnset      x-url: /
-   RespUnset      x-host: 
-   RespUnset      Via: 1.1 varnish (Varnish/6.0)
-   RespUnset      X-Varnish: 164200 3
-   VCL_return     deliver
-   Timestamp      Process: 1676987476.561898 0.000066 0.000066
-   RespHeader     Connection: close
-   Timestamp      Resp: 1676987476.561937 0.000105 0.000040
-   ReqAcct        142 0 142 177 226 403
-   End

进行TCP转储,此请求位于本地主机中,实际上未到达Apache所在的服务器。

varnishd如下所示:

[Unit]
Description=Varnish Cache, a high-performance HTTP accelerator
After=network-online.target

[Service]
Type=forking
KillMode=process

# Maximum number of open files (for ulimit -n)
LimitNOFILE=131072

# Locked shared memory - should suffice to lock the shared memory log
# (varnishd -l argument)
# Default log size is 80MB vsl + 1M vsm + header -> 82MB
# unit is bytes
LimitMEMLOCK=85983232

# Enable this to avoid "fork failed" on reload.
TasksMax=infinity

# Maximum size of the corefile.
LimitCORE=infinity

ExecStart=/usr/sbin/varnishd -a :6081 -f /etc/varnish/default.vcl -s malloc,2g -p http_max_hdr=1024 -p http_resp_hdr_len=65536
ExecReload=/usr/sbin/varnishreload

[Install]
WantedBy=multi-user.target
nkhmeac6

nkhmeac61#

问题是你收到了一个HTTP/1.0请求,它不包含Host头,因为那个版本的协议不支持它。
然而,Varnish将其转换为一个HTTP/1.1请求,这需要使用一个Host头,如www.example.com中所述https://www.varnish-software.com/developers/tutorials/varnish-builtin-vcl/#enforce-the-host-header,内置的VCL强制执行该头,如果找不到该头,则返回一个HTTP/1.1 400 Bad Request
我很确定这与您的TLS代理中缺少配置有关。请确保它发送HTTP/1.1流量,并且问题应该会自行解决。

相关问题