spantaleev / matrix-docker-ansible-deploy

🐳 Matrix (An open network for secure, decentralized communication) server setup using Ansible and Docker
GNU Affero General Public License v3.0
4.64k stars 1.01k forks source link

caddy2 and .well-known #1080

Open bhyde opened 3 years ago

bhyde commented 3 years ago

The instructions for "configuring well known" are, like usual, concise. Possible too concise. At least for caddy2.

A note might be added:

Beware that caddy's redir directive has very high priority. For example you may need to us a route directive to work around that.

spantaleev commented 3 years ago

This is about examples/caddy/matrix-util?

Does redir have a higher priority than proxy /.well-known/acme-challenge http://127.0.0.1:2402 above it?

Is it a problem with this default config or if you do something else? What would be a better way to do things? Should we add some more examples to that config?

bhyde commented 3 years ago

Does redir have a higher priority than proxy /.well-known/acme-challenge http://127.0.0.1:2402 above it? Exactly right. Though since Caddy prides it's self in handling let's encrypt for it's users it is vanishing rare that any of them ever configure an acme-challenge.

And, the route directive is used to force the order/priority.

I made an example you maybe able to use. But first, I posted it in the caddy forum in hope of getting some code review.

bhyde commented 3 years ago

The example config discussed here has been given an approving nod, and is working for me (finger's crossed).

spantaleev commented 3 years ago

I'm somewhat confused. Which file would you like to get these changes put into?

Perhaps you could submit a PR?

QEDeD commented 2 years ago

I'm pretty sure bhyde is referring to the instructions here: https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/configuring-well-known.md#configuring-service-discovery-via-well-known

The suggestion for Caddy 2 is:

For Caddy 2, it would be something like this:

reverse_proxy /.well-known/matrix/* https://matrix.DOMAIN {
  header_up Host {http.reverse_proxy.upstream.hostport}
}

I've tried using this suggested configuration, but it results in the following error repeating infinitely and blocking my Caddy docker from starting:

{"level":"info","ts":1628424925.7943344,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
run: adapting config using caddyfile: /etc/caddy/Caddyfile:2: unrecognized directive: header_up

However, I also tried the instructions provided by @bhyde, but the federation tester is giving me the error:

Connection Errors
Unable to decode JSON from remote server: EOF
aaronraimist commented 2 years ago

@QEDeD maybe take a look at https://caddy.community/t/unrecognized-directive-header-up/10319/13