Use config modules in Caddyfile

1. Output of caddy version:

2.5.1

2. How I run Caddy:

Caddyfile:

<my_domain>:443 {
reverse_proxy localhost:11000
}

a. System environment:

CentOS-7

d. My complete Caddy config:

This is the autosave.json after startup (I don’t set a manual config):

{
   "apps":{
      "http":{
         "servers":{
            "srv0":{
               "listen":[
                  ":443"
               ],
               "routes":[
                  {
                     "handle":[
                        {
                           "handler":"subroute",
                           "routes":[
                              {
                                 "handle":[
                                    {
                                       "handler":"reverse_proxy",
                                       "upstreams":[
                                          {
                                             "dial":"localhost:11000"
                                          }
                                       ]
                                    }
                                 ]
                              }
                           ]
                        }
                     ],
                     "match":[
                        {
                           "host":[
                              "<my_domain>.com"
                           ]
                        }
                     ],
                     "terminal":true
                  }
               ]
            }
         }
      }
   }
}

3. The problem I’m having:

I would like to implement a config module (see 6.) into my Caddyfile, so I do not have to care about two files at startup. Is it possible to implement this into the Caddyfile?

6. Links to relevant resources:

tls.certificates.load_pem

Apparently they are loaded like this.
Would be nice to have a link between corresponding config modules and caddy directives.

The page you linked to is for JSON config, not the Caddyfile. They aren’t the same thing. They aren’t compatible.

The Caddyfile is an adapter that produces a JSON config. Caddy’s underlying config language is JSON, but most users use the Caddyfile because it’s easier to use.

That said, the way Caddy is designed, a particular module may be used in many different places in the JSON config, as a “guest module”. For example, the load_pem module gets used in apps > tls > certificates in the JSON config, but it may be used somewhere else as well. For that reason, it’s not possible to link from a particular module’s page to the place where it can be used, because it can be infinite.

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.