• [Caddy2] Caddyfile 概念预览


    结构

    块:

    所有的指令必须在 { } 块中,如果只有一个站点,则块标记可以省略。

    全局的配置块可以放在最上方,其次是站点的配置块。

    指令:

    指令是服务于站点配置的关键词。

    关键词和引号:

    空格在 Caddyfile 指令中很重要,如果希望带空格的字符为一个值,需要给它们加上引号。

    directive abc def
    directive "abc def"
    directive ""abc def""
    directive `"foo bar"`

    地址

    地址位于块的最上方。

    有效的地址如下,

    • localhost
    • example.com
    • :443
    • http://example.com
    • localhost:8080
    • 127.0.0.1
    • [::1]:2015
    • example.com/foo/*
    • *.example.com
    • http://

    如果您的站点地址包含主机名或IP地址,则启用自动HTTPS。

    但是,此行为是纯隐式的,因此它永远不会覆盖任何显式配置。

    例如,如果站点的地址为http://example.com,则不会激活自动HTTPS。

    通过把地址写在一起可以匹配多个站点,地址必须是唯一的。

    localhost:8080, example.com, www.example.com {
    }

    或者
    localhost:8080,
    example.com,
    www.example.com

    匹配器

    请求匹配器用于对请求进行分类。

    root *           /var/www  # matcher token: *
    root /index.html /var/www  # matcher token: /index.html
    root @post       /var/www  # matcher token: @post

    更多关于 Matcher

    占位符

    左边的简记符等价于右边的。

    {dir} {http.request.uri.path.dir}
    {file} {http.request.uri.path.file}
    {header.*} {http.request.header.*}
    {host} {http.request.host}
    {labels.*} {http.request.host.labels.*}
    {hostport} {http.request.hostport}
    {port} {http.request.port}
    {method} {http.request.method}
    {path} {http.request.uri.path}
    {path.*} {http.request.uri.path.*}
    {query} {http.request.uri.query}
    {query.*} {http.request.uri.query.*}
    {re.*.*} {http.regexp.*.*}
    {remote} {http.request.remote}
    {remote_host} {http.request.remote.host}
    {remote_port} {http.request.remote.port}
    {scheme} {http.request.scheme}
    {uri} {http.request.uri}
    {tls_cipher} {http.request.tls.cipher_suite}
    {tls_version} {http.request.tls.version}
    {tls_client_fingerprint} {http.request.tls.client.fingerprint}
    {tls_client_issuer} {http.request.tls.client.issuer}
    {tls_client_serial} {http.request.tls.client.serial}
    {tls_client_subject} {http.request.tls.client.subject}

    代码片段

    代码片段是特殊的块,命名用扩展包起来。

    (redirect) {
        @http {
            scheme http
        }
        redir @http https://{host}{uri}
    }

    然后,可以在其它地方引入使用。

    import redirect

    注释

    注释使用 # 号,必须在行首或者行尾。

    环境变量

    如果配置依赖于环境变量,可以使用如下方式

    {$SITE_ADDRESS}

    在运行前会被解析为正确的值。

    如果希望在运行时解析,你可以使用标准的 {env.*} 占位符。

    全局选项

    全局选项是没有 key 的块。

    {
        ...
    }

    如果全局选项存在,它必须是配置中的第一个块。

    它用于设置全局应用的选项,或不适用于特定的任何站点。在内部,只能设置全局选项。您不能在其中使用常规站点指令。

    更多

    [Caddy] The Caddy Web Server 常见 Caddyfile 模式

    Ref:https://caddyserver.com/docs/caddyfile/concepts

    Link:https://www.cnblogs.com/farwish/p/13100103.html

  • 相关阅读:
    Eclipse遇到Initializing Java Tooling终极解决办法
    Quartz定时任务框架理解
    Quartz定时任务调度
    jQueryEasyUI Messager基本使用
    转一篇关于Log4j的介绍文章,很详细
    android联系人
    手机中预置联系人(姓名,号码,头像)
    android获取硬件信息
    Sumatra pdf更改起始页面的黄色颜色
    Eclipse背景颜色设置(设置成豆沙绿色保护眼睛,码农保护色)
  • 原文地址:https://www.cnblogs.com/farwish/p/13100103.html
Copyright © 2020-2023  润新知