caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
56.45k stars 3.96k forks source link

Caddyfile: Got error while trying to serve an http to https redirect aside the https virtual host. #3572

Closed sparkcyf closed 4 years ago

sparkcyf commented 4 years ago

What did you do?

I started caddy2 with two virtual hosts with the same domain example.com.

The first virtual host is https://example.com, which server an static site. The second virtual host is http://example.com, which redirects the http traffic to the first virtual host.

The CaddyFile looks like this:

{
    auto_https off
}

http://example.com {
redir https://example.com{uri} permanent
}

https://example.com {
}
    tls cert.crt cert.key
    root * /var/www/html
    file_server
}

What did you expect to see?

The caddy could redirect the Http traffic to the Https virtual host and server the virtual hosts normally.

What did you see instead?

caddy did not startup and failed with the following exception adapting config using caddyfile: hostname appears in more than one automation policy, making certificate management ambiguous: example.com

Which is quite similar to the error got in #3351 and #3550

Caddy version

2.1.1

I indicates that this error was caused by something related to the certificate automation, however I've disabled auto_https at the beginning and use my own certificate. This issues hasn't been happened on caddy1 before.

Thanks.

francislavoie commented 4 years ago

Well, it looks like you have a syntax error in that config. You have an extra }.

When I try to adapt that Caddyfile I don't get that error. Please provide your full, unredacted Caddyfile so we can properly replicate the issue you're having.

That said, I think 7bfe5b6c9520daabb71d22f24470bc91eca931d9 is a relevant fix, so you can try the latest by building from source, or you can use the latest CI artifacts.

sparkcyf commented 4 years ago

Hi, the full Caddyfile is presented below:

{
    auto_https off
}

http://example.com {
bind 10.0.0.1
redir https://example.com{uri} permanent
}

https://example.com {
bind 10.0.0.1
    tls /path/to/cert.crt /path/to/cert.key
    root * /var/www/html
    file_server
}

I've also verify that if I delete the HTTP virtual host (http://example.com), the caddy could works well.

francislavoie commented 4 years ago

Have you tried with the latest build of Caddy as I asked above? Works for me.

Closing because this has already been fixed on master.

sparkcyf commented 4 years ago

Have you tried with the latest build of Caddy as I asked above? Works for me.

Closing because this has already been fixed on master.

Hi, the caddy works well after using the latest CI artifacts.

Thanks for your help!