Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sparkcyf opened this issue Jul 11, 2020 · 4 comments
Labels
duplicate 🖇️ This issue or pull request already exists

Comments

@sparkcyf
Copy link

sparkcyf commented Jul 11, 2020

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
Copy link
Member

francislavoie commented Jul 11, 2020

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 7bfe5b6 is a relevant fix, so you can try the latest by building from source, or you can use the latest CI artifacts.

@francislavoie francislavoie added the needs info 📭 Requires more information label Jul 11, 2020
@sparkcyf
Copy link
Author

sparkcyf commented Jul 11, 2020

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
Copy link
Member

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.

@francislavoie francislavoie added invalid ❓ This doesn't seem right duplicate 🖇️ This issue or pull request already exists and removed needs info 📭 Requires more information invalid ❓ This doesn't seem right labels Jul 11, 2020
@sparkcyf
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate 🖇️ This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants