Caddy 2 cannot disable automatic https redirect

I want to use automatic tls for all domains and forwarding all http/https traffic to the backend app.

I have copied below the error I am getting. How can I make this work?

docker run -i -t --rm -v /opt/caddy/Caddyfile:/etc/caddy/Caddyfile caddy/caddy:alpine

2020/03/31 19:16:40.288 INFO using provided configuration {“config_file”: “/etc/caddy/Caddyfile”, “config_adapter”: “caddyfile”}
run: adapting config using caddyfile: cannot make a TLS automation policy from a server block that has a host-less address when there are other server block addresses lacking a host

cat /opt/caddy/Caddyfile

    {
        email foo@example.com
    }
    http://, https:// {
        log stdout
        reverse_proxy web:5000
    }

This seems to be the option I am after:

How do I set that? I tried something like this but didn’t get anywhere:

        {
        email foo@example.com
    }
    * {
        log stdout
        reverse_proxy web:5000
        automatic_https {
            disable_redirects true
        }
    }

To disable only HTTP->HTTPS redirects, you have to use the JSON for now.

Can you provide an example translation? I couldn’t seem to get the json right

What have you tried so far? I’ll see if I can help fix it up.

Be very careful with that Docker command you used, you need to make sure you define the volumes for the config and data directories to avoid data loss and potentially hitting Let’s Encrypt rate limits. See the README in the caddy-docker repo!

1 Like

Just testing startup but thanks for the notice =)

I am thinking this looks right. Trying now to figure out how to use the json adapter. Looks like the beta image doesn’t ship with either adapter?

cat /opt/caddy/Caddyfile

{
    "apps": {
        "http": {
            "servers": {
                "srv0": {
                    "listen": [
                        ":80",
                        ":443"
                    ],
                    "routes": [
                        {
                            "automatic_https": {
                                "disable_redirects": true
                            },
                            "match": [
                                {
                                    "host": [
                                        "*"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "handle": [
                                                {
                                                    "handler": "reverse_proxy",
                                                    "upstreams": [
                                                        {
                                                            "dial": "web:5000"
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ],
                            "terminal": true
                        }
                    ]
                }
            }
        },
        "tls": {
            "automation": {
                "policies": [
                    {
                        "issuer": {
                            "email": "foo@example.com",
                            "module": "acme"
                        }
                    }
                ]
            }
        }

    }
}

docker run -i -t --rm -v /opt/caddy/Caddyfile:/etc/caddy/Caddyfile caddy/caddy:alpine caddy run --config=/etc/caddy/Caddyfile --adapter=jsonc

2020/04/01 12:36:44.039 INFO using provided configuration {“config_file”: “/etc/caddy/Caddyfile”, “config_adapter”: “jsonc”}
run: unrecognized config adapter: jsonc

docker run -i -t --rm -v /opt/caddy/Caddyfile:/etc/caddy/Caddyfile caddy/caddy:alpine caddy run --config=/etc/caddy/Caddyfile --adapter=json5

2020/04/01 12:36:37.229 INFO using provided configuration {“config_file”: “/etc/caddy/Caddyfile”, “config_adapter”: “json5”}
run: unrecognized config adapter: json5

docker run -i -t --rm -v /opt/caddy/Caddyfile:/etc/caddy/Caddyfile caddy/caddy:alpine caddy run --config=/etc/caddy/Caddyfile --adapter=json

2020/04/01 12:36:40.625 INFO using provided configuration {“config_file”: “/etc/caddy/Caddyfile”, “config_adapter”: “json”}
run: unrecognized config adapter: json

docker run -i -t --rm -v /opt/caddy/Caddyfile:/etc/caddy/Caddyfile caddy/caddy:alpine caddy run --config=/etc/caddy/Caddyfile

2020/04/01 12:49:25.546 INFO using provided configuration {“config_file”: “/etc/caddy/Caddyfile”, “config_adapter”: “”}
run: adapting config using caddyfile: /etc/caddy/Caddyfile:61 - Error during parsing: Unexpected EOF

Figured that out. Still not running to test the beta out though

docker run -i -t --rm -v /opt/caddy/Caddyfile:/etc/caddy/Caddyfile.json caddy/caddy:alpine caddy run --config=/etc/caddy/Caddyfile.json

2020/04/01 13:06:11.305 INFO using provided configuration {“config_file”: “/etc/caddy/Caddyfile.json”, “config_adapter”: “”}
2020/04/01 13:06:15.315 INFO admin admin endpoint started {“address”: “localhost:2019”, “enforce_origin”: false, “origins”: [“localhost:2019”]}
run: loading initial config: loading new config: loading http app module: decoding module config: http: json: unknown field “automatic_https”

Seems to be working with:

{
"apps": {
    "http": {
        "servers": {
            "srv0": {
                "automatic_https": {
                    "disable_redirects": true
                },
                "listen": [
                    ":80",
                    ":443"
                ],
                "routes": [
                    {
                        "match": [
                            {
                                "host": [
                                    "*"
                                ]
                            }
                        ],
                        "handle": [
                            {
                                "handler": "subroute",
                                "routes": [
                                    {
                                        "handle": [
                                            {
                                                "handler": "reverse_proxy",
                                                "upstreams": [
                                                    {
                                                        "dial": "web:5000"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ],
                        "terminal": true
                    }
                ]
            }
        }
    },
    "tls": {
        "automation": {
            "policies": [
                {
                    "issuer": {
                        "email": "foo@example.com",
                        "module": "acme"
                    }
                }
            ]
        }
    }

}

}

1 Like

Thanks for posting your solution! Glad you got it working. You can always consult the JSON structure in the docs to know where fields go.

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