gpt4 book ai didi

varnish - 如何在 Varnish 中的 default.vcl 中创建自定义函数?

转载 作者:行者123 更新时间:2023-12-03 17:44:55 24 4
gpt4 key购买 nike

我的 vcl 中有重复代码,我想创建自定义函数而不嵌入内联 C 代码。可能吗?

最佳答案

你可以像这样定义一个自定义子程序

sub my_subroutine {
...
}

然后这样调用它:

call my_subroutine;

发件人:http://book.varnish-software.com/4.0/chapters/VCL_Basics.html

Subroutines in VCL take neither arguments nor return values. Each subroutine terminates by calling return (action), where action is a keyword that indicates the desired outcome. Subroutines may inspect and manipulate HTTP header fields and various other aspects of each request. Subroutines instruct how requests are handled.

Subroutine example:

sub pipe_if_local { if (client.ip ~ local) { return (pipe); } }

To call a subroutine, use the call keyword followed by the subroutine’s name:

call pipe_if_local;

Varnish has built-in subroutines that are hook into the Varnish workflow. These built-in subroutines are all named vcl_*. Your own subroutines cannot start their name with vcl_.

关于varnish - 如何在 Varnish 中的 default.vcl 中创建自定义函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34957036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com