Skip to content

Instantly share code, notes, and snippets.

@fizzyade
Last active March 25, 2024 22:58
Show Gist options
  • Select an option

  • Save fizzyade/8b7978c9001c9dde987c16bdfa322a01 to your computer and use it in GitHub Desktop.

Select an option

Save fizzyade/8b7978c9001c9dde987c16bdfa322a01 to your computer and use it in GitHub Desktop.
An example of a Caddy 2 JSON configuration file for a reverse proxy that uses the Cloudflare DNS module
{
  "apps": {
    "http": {
      "servers": {
        "example": {
          "listen": [
            ":80",
            ":443"
          ],
          "routes": [
            {
              "match": [
                {
                  "host": [
                    "mydomain.co.uk"
                  ]
                }
              ],
              "handle": [
                {
                  "handler": "subroute",
                  "routes": [
                    {
                      "handle": [
                        {
                          "handler": "reverse_proxy",
                          "upstreams": [
                            {
                              "dial": "localhost:8080"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    },
    "tls": {
      "automation": {
        "policies": [
          {
            "subjects": [
              "mydomain.co.uk"
            ],
            "issuer": {
              "challenges": {
                "dns": {
                  "provider": {
                    "api_token": "<api token goes here>",
                    "name": "cloudflare"
                  }
                }
              },
              "email": "<email address used for cloudflare account>",
              "module": "acme"
            }
          }
        ]
      }
    }
  }
}
@yurenchen000
Copy link

json format is not easy for manual.
so here is a caddyfile:

  • https @ :3443
  • file browser @ /public
# global conf
{
    auto_https disable_redirects
    #acme_dns dnspod your_id,your_token
}

# server
your.domain.com:3443 {
    #root * /srv/http

    tls {
        dns dnspod your_id,your_token
    }

    handle /public/* {
        root ./down
        uri strip_prefix /public
        file_server browse
    }

    file_server
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment