File manager - Edit - /usr/share/doc/varnish/html/users-guide/vcl-syntax.html
Back
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>VCL Syntax — Varnish version 7.1.1 documentation</title> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/classic.css" type="text/css" /> <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script src="../_static/jquery.js"></script> <script src="../_static/underscore.js"></script> <script src="../_static/doctools.js"></script> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="next" title="Built-in subroutines" href="vcl-built-in-subs.html" /> <link rel="prev" title="VCL - Varnish Configuration Language" href="vcl.html" /> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="vcl-built-in-subs.html" title="Built-in subroutines" accesskey="N">next</a> |</li> <li class="right" > <a href="vcl.html" title="VCL - Varnish Configuration Language" accesskey="P">previous</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">Varnish version 7.1.1 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" >The Varnish Users Guide</a> »</li> <li class="nav-item nav-item-2"><a href="vcl.html" accesskey="U">VCL - Varnish Configuration Language</a> »</li> <li class="nav-item nav-item-this"><a href="">VCL Syntax</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="vcl-syntax"> <h1>VCL Syntax<a class="headerlink" href="#vcl-syntax" title="Permalink to this headline">¶</a></h1> <p>VCL has inherited a lot from C and it reads much like simple C or Perl.</p> <p>Blocks are delimited by curly brackets, statements end with semicolons, and comments may be written as in C, C++ or Perl according to your own preferences.</p> <p>Note that VCL doesn’t contain any loops or jump statements.</p> <p>This section provides an outline of the more important parts of the syntax. For a full documentation of VCL syntax please see <a class="reference internal" href="../reference/vcl.html#vcl-7"><span class="std std-ref">VCL</span></a> in the reference.</p> <div class="section" id="strings"> <h2>Strings<a class="headerlink" href="#strings" title="Permalink to this headline">¶</a></h2> <p>Basic strings are enclosed in ” … “, and may not contain newlines.</p> <p>Backslash is not special, so for instance in <cite>regsub()</cite> you do not need to do the “count-the-backslashes” polka:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">regsub</span><span class="p">(</span><span class="s2">"barf"</span><span class="p">,</span> <span class="s2">"(b)(a)(r)(f)"</span><span class="p">,</span> <span class="s2">"</span><span class="se">\4\3\2</span><span class="s2">p"</span><span class="p">)</span> <span class="o">-></span> <span class="s2">"frap"</span> </pre></div> </div> <p>Long strings are enclosed in {” … “} or “”” … “””. They may contain any character including “, newline and other control characters except for the NUL (0x00) character. If you really want NUL characters in a string there is a VMOD that makes it possible to create such strings.</p> </div> <div class="section" id="access-control-lists-acls"> <span id="vcl-syntax-acl"></span><h2>Access control lists (ACLs)<a class="headerlink" href="#access-control-lists-acls" title="Permalink to this headline">¶</a></h2> <p>An ACL declaration creates and initializes a named access control list which can later be used to match client addresses:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>acl local { "localhost"; // myself "192.0.2.0"/24; // and everyone on the local network ! "192.0.2.23"; // except for the dialin router } </pre></div> </div> <p>If an ACL entry specifies a host name which Varnish is unable to resolve, it will match any address it is compared to. Consequently, if it is preceded by a negation mark, it will reject any address it is compared to, which may not be what you intended. If the entry is enclosed in parentheses, however, it will simply be ignored.</p> <p>To match an IP address against an ACL, simply use the match operator:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">ip</span> <span class="o">~</span> <span class="n">local</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="p">(</span><span class="n">pipe</span><span class="p">);</span> <span class="p">}</span> </pre></div> </div> <p>In Varnish versions before 7.0, ACLs would always emit a <cite>VCL_acl</cite> record in the VSL log, from 7.0 and forward, this must be explicitly enabled by specifying the <cite>+log</cite> flag:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>acl local +log { "localhost"; // myself "192.0.2.0"/24; // and everyone on the local network ! "192.0.2.23"; // except for the dialin router } </pre></div> </div> </div> <div class="section" id="operators"> <h2>Operators<a class="headerlink" href="#operators" title="Permalink to this headline">¶</a></h2> <p>The following operators are available in VCL. See the examples further down for, uhm, examples.</p> <dl class="simple"> <dt>=</dt><dd><p>Assignment operator.</p> </dd> </dl> <dl class="simple"> <dt>==</dt><dd><p>Comparison.</p> </dd> </dl> <dl class="simple"> <dt>~</dt><dd><p>Match. Can either be used with regular expressions or ACLs.</p> </dd> </dl> <dl class="simple"> <dt>!</dt><dd><p>Negation.</p> </dd> </dl> <dl class="simple"> <dt>&&</dt><dd><p>Logical <em>and</em></p> </dd> </dl> <dl class="simple"> <dt>||</dt><dd><p>Logical <em>or</em></p> </dd> </dl> </div> <div class="section" id="built-in-subroutines"> <h2>Built in subroutines<a class="headerlink" href="#built-in-subroutines" title="Permalink to this headline">¶</a></h2> <p>Varnish has quite a few built-in subroutines that are called for each transaction as it flows through Varnish. These built-in subroutines are all named <code class="docutils literal notranslate"><span class="pre">vcl_*</span></code> and are explained in <a class="reference internal" href="vcl-built-in-subs.html#vcl-built-in-subs"><span class="std std-ref">Built-in subroutines</span></a>.</p> <p>Processing in built-in subroutines ends with <code class="docutils literal notranslate"><span class="pre">return</span> <span class="pre">(<action>)</span></code> (see <a class="reference internal" href="vcl-actions.html#user-guide-vcl-actions"><span class="std std-ref">Actions</span></a>).</p> <p>The <a class="reference internal" href="vcl-built-in-code.html#vcl-built-in-code"><span class="std std-ref">Built-in VCL</span></a> also contains custom assistant subroutines called by the built-in subroutines, also prefixed with <code class="docutils literal notranslate"><span class="pre">vcl_</span></code>.</p> </div> <div class="section" id="custom-subroutines"> <h2>Custom subroutines<a class="headerlink" href="#custom-subroutines" title="Permalink to this headline">¶</a></h2> <p>You can write your own subroutines, whose names cannot start with <code class="docutils literal notranslate"><span class="pre">vcl_</span></code>.</p> <p>A subroutine is typically used to group code for legibility or reusability:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sub</span> <span class="n">pipe_if_local</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">ip</span> <span class="o">~</span> <span class="n">local</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="p">(</span><span class="n">pipe</span><span class="p">);</span> <span class="p">}</span> <span class="p">}</span> </pre></div> </div> <p>To call a subroutine, use the <code class="docutils literal notranslate"><span class="pre">call</span></code> keyword followed by the subroutine’s name:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">call</span> <span class="n">pipe_if_local</span><span class="p">;</span> </pre></div> </div> <p>Custom subroutines in VCL do not take arguments, nor do they return values.</p> <p><code class="docutils literal notranslate"><span class="pre">return</span> <span class="pre">(<action>)</span></code> (see <a class="reference internal" href="vcl-actions.html#user-guide-vcl-actions"><span class="std std-ref">Actions</span></a>) as shown in the example above returns all the way from the top level built in subroutine (see <a class="reference internal" href="vcl-built-in-subs.html#vcl-built-in-subs"><span class="std std-ref">Built-in subroutines</span></a>) which, possibly through multiple steps, lead to the call of the custom subroutine.</p> <p><code class="docutils literal notranslate"><span class="pre">return</span></code> without an action resumes execution after the <code class="docutils literal notranslate"><span class="pre">call</span></code> statement of the calling subroutine.</p> </div> </div> <div class="clearer"></div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">Table of Contents</a></h3> <ul> <li><a class="reference internal" href="#">VCL Syntax</a><ul> <li><a class="reference internal" href="#strings">Strings</a></li> <li><a class="reference internal" href="#access-control-lists-acls">Access control lists (ACLs)</a></li> <li><a class="reference internal" href="#operators">Operators</a></li> <li><a class="reference internal" href="#built-in-subroutines">Built in subroutines</a></li> <li><a class="reference internal" href="#custom-subroutines">Custom subroutines</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="vcl.html" title="previous chapter">VCL - Varnish Configuration Language</a></p> <h4>Next topic</h4> <p class="topless"><a href="vcl-built-in-subs.html" title="next chapter">Built-in subroutines</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/users-guide/vcl-syntax.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3 id="searchlabel">Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" aria-labelledby="searchlabel" /> <input type="submit" value="Go" /> </form> </div> </div> <script>$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="vcl-built-in-subs.html" title="Built-in subroutines" >next</a> |</li> <li class="right" > <a href="vcl.html" title="VCL - Varnish Configuration Language" >previous</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">Varnish version 7.1.1 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" >The Varnish Users Guide</a> »</li> <li class="nav-item nav-item-2"><a href="vcl.html" >VCL - Varnish Configuration Language</a> »</li> <li class="nav-item nav-item-this"><a href="">VCL Syntax</a></li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2010-2014, Varnish Software AS. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.4.3. </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 8.2.9 | Generation time: 0.1 |
proxy
|
phpinfo
|
Settings