在 Varnish 中未设置 - 语法错误

发布于 2024-09-02 04:21:05 字数 319 浏览 4 评论 0原文

我试图从 Varnish 中隐藏 Apache 对每个请求返回的“服务器”标头。

在 sub vcl_fetch: 中使用

unset obj.http.Server;

Varnish 启动时我得到:

Expected action, 'if' or '}'
(/etc/varnish/default.vcl Line 43 Pos 9)
    unset obj.http.Server;
--------#####-----------------

有什么想法吗?

I'm trying to hide the "Server" header returned by Apache on every request, from Varnish.

Using in sub vcl_fetch:

unset obj.http.Server;

on Varnish start I get:

Expected action, 'if' or '}'
(/etc/varnish/default.vcl Line 43 Pos 9)
    unset obj.http.Server;
--------#####-----------------

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

末が日狂欢 2024-09-09 04:21:05

在最近的版本(2.1 系列)中,响应对象称为 beresp,vcl_fetch 中类似的东西确实工作(我刚刚在 Varnish 2.1.0 上测试了它):

unset beresp.http.Server;

我安装了您正在使用的版本( 1.1.2)并得到了与您提到的完全相同的行为;看来 unset 关键字不起作用,至少在 vcl_fetch 函数中不起作用。这很奇怪,因为我发现至少有一个例子提到使用 unset 来实现确切目的

如果可能的话,我建议升级到最新的 Varnish,因为我认为,如果您观察到的未设置行为是一个错误,团队不太可能愿意修复它。

除此之外,您可能想尝试将服务器设置为其他内容:

set obj.http.Server = "";
set obj.http.Server = "BogoServer Whatever"; 

假设您的目标是隐藏服务器签名。如果你想要的是完全消除标题,我敢说你的 Varnish 版本无法做到这一点。

In recent versions (2.1 series) the response object is called beresp, and something like this in vcl_fetch does work (I just tested it on Varnish 2.1.0):

unset beresp.http.Server;

I installed the version you're using (1.1.2) and got the exact same behavior you mention; it would appear the unset keyword doesn't work, at least not in the vcl_fetch function. This is odd, as at least one example I found mentions using unset for that exact purpose.

If possible, I'd suggest upgrading to the latest Varnish, as I think it unlikely that, if the unset behavior you observed is a bug, the team will be willing to fix it.

Barring that, you might want to try setting Server to something else:

set obj.http.Server = "";
set obj.http.Server = "BogoServer Whatever"; 

Assuming your objective is to hide the server signature. If what you want is to eliminate the header altogether, I'd venture to say it can't be done with your version of Varnish.

分開簡單 2024-09-09 04:21:05

最终修复了它。

我在 vcl_recv 中有一个 return(pipe) ,这使得 varnish 永远不会进入我取消设置标头的 vcl_fetch 。

Fixed it eventually.

I had a return(pipe) in vcl_recv that made varnish never go into vcl_fetch where I was unsetting the header.

淡看悲欢离合 2024-09-09 04:21:05

我正在使用清漆 1.1.2
也用beresp进行测试,也出现同样的错误。

好像未设置有问题。
这是完整的获取:

sub vcl_fetch {
    unset obj.http.Server;
    # force minimum ttl of 6 hours
    if (obj.ttl < 6h) {
            set obj.ttl = 6h;
    }
}

I'm using Varnish 1.1.2
Also tested with beresp and the same error occurs.

It's like it's something wrong with unset.
Here's the full fetch:

sub vcl_fetch {
    unset obj.http.Server;
    # force minimum ttl of 6 hours
    if (obj.ttl < 6h) {
            set obj.ttl = 6h;
    }
}
月野兔 2024-09-09 04:21:05

我抽出时间安装了 Varnish 2.1.2,这是迄今为止的最新版本。
我不再收到任何语法错误,但未应用所需的效果。这个弹性标头仍然存在。

sub vcl_fetch {
    unset beresp.http.Server;
    set beresp.http.Server = "Apache";
}

我使用 Firebug 来查看标题,这就是我所看到的:

Server  Apache/2.2.9 (Debian)

我尝试了一些变体,例如仅取消设置和不设置,但没有任何效果。

会不会是逻辑问题?也许未设置需要放置在不同的中。我尝试将其放入 vcl_miss 和 vcl_deliver 中。两次都收到“变量'beresp.http.Server'无法在方法中访问..”。

我还尝试设置自定义标头并将其删除。那也没用。

I got around to install Varnish 2.1.2 which is the latest version to date.
I no longer get any syntax errors, but the desired effect is not applied. This resilient header is still there.

sub vcl_fetch {
    unset beresp.http.Server;
    set beresp.http.Server = "Apache";
}

I use Firebug to peek at the headers, here's what I see:

Server  Apache/2.2.9 (Debian)

I've tried some variations like just unsetting and not setting, nothing works.

Can it be a problem of logic? Maybe the unset needs to be placed in a different sub. I tried placing it in both vcl_miss and vcl_deliver. Got "Variable 'beresp.http.Server' not accessible in method.." both times.

I've also tried setting a custom header and removing it. That didn't work either.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文