Varnish基本配置文件抛出" VCL编译失败"当我尝试使用std.syslog时。为什么?

时间:2017-04-10 22:06:09

标签: varnish varnish-vcl varnish-4

我有一个简单的VCL文件如下:

vcl 4.0;

import std;

backend default {
    .host = "127.0.0.1";
    .port = "3333";
}

sub vcl_recv {
    std.log("req.host: "+req.host);
}

sub vcl_backend_response {

}

sub vcl_deliver {

}

当我尝试在Mac上使用此配置启动varnishd时,出现以下错误:

Error:
Message from VCC-compiler:
Symbol not found: 'req.host' (expected type STRING):
('/Users/jononomo/dev/my_project/deploy/testing.vcl' Line 30 Pos 26)
    std.log("req.host: "+req.host);
-------------------------########--

('/Users/jononomo/dev/my_project/deploy/testing.vcl' Line 30 Pos 5) -- ('/Users/jononomo/dev/my_project/deploy/testing.vcl' Line 30 Pos 25)
    std.log("req.host: "+req.host);
----#####################----------

Running VCC-compiler failed, exited with 2
VCL compilation failed

我尝试过这一行的不同变体:

std.log("req.host: "+req.host);

如:

std.log(req.host: '+req.host);
std.log("req.host: ",req.host);
std.log('req.host: ',req.host);
std.log('hello');

但它们都不起作用。

如何从我的VCL文件中进行简单的日志记录?

感谢。

更新:std.log("hello")似乎在编译......但是,我需要记录有关请求对象的信息,并且reqrequest等不存在。

1 个答案:

答案 0 :(得分:1)

改为使用req.http.host

vcl 4.0;

import std;

backend default {
    .host = "127.0.0.1";
    .port = "3333";
}

sub vcl_recv {
    std.log("req.host: " + req.http.host);
}

sub vcl_backend_response {

}

sub vcl_deliver {

}