How can I use proxy_ssl_name for SNI in Caddy 2

Hi!

1. My Caddy version (caddy version):

v2.0.0-rc.3

a. System environment:

Linux

2. The problem I’m having:

proxy_ssl_name for SNI should work with Caddy 2:

But I can’t find anything in the documentation.
How I can set proxy_ssl_name in the Caddyfile?

This is my current Caddyfile:


:8000

reverse_proxy {
	to https://mydomain.com
	transport http {
               // this is not working:
		//tls {
		//	server_name mydomain.com
		//}
	}
	header_up X-Real-IP {http.reverse_proxy.upstream.remote}
	header_up X-Forwarded-For {http.reverse_proxy.upstream.remote}
	header_up X-Forwarded-Port {http.reverse_proxy.upstream.hostport}
	header_up X-Forwarded-Proto {http.reverse_proxy.upstream.scheme}
}

Thank you

I think you’re looking to set the Host field to mydomain.com?

:8000

reverse_proxy https://mydomain.com {
	header_up Host mydomain.com
	header_up X-Real-IP {http.request.remote.host}
	header_up X-Forwarded-Port {http.request.port}
	header_up X-Forwarded-Proto {http.request.proto}
}

X-Forwarded-For is set automatically for you, and X-Forwarded-Proto will be set automatically as of the next release.

By default Host is set to the SNI of the original request. I think you’re looking to override that with mydomain.com instead?

@francislavoie The Host header is for the application layer (HTTP); Stefan needs ServerName set in the TLS handshake.

@sgasser The website docs aren’t fully updated yet, but you can set the server_name field of the HTTP transport’s TLS settings here: Modules - Caddy Documentation

Thanks @matt and @francislavoie - what a great community :heart_eyes:

How can I transform this Modules - Caddy Documentation to the Cadddyfile?

I tried:

:8000

reverse_proxy {
	to https://mydomain.com
	transport http {
		tls {
			server_name https://mydomain.com
		}
	}
	header_up X-Real-IP {http.reverse_proxy.upstream.remote}
	header_up X-Forwarded-For {http.reverse_proxy.upstream.remote}
	header_up X-Forwarded-Port {http.reverse_proxy.upstream.hostport}
	header_up X-Forwarded-Proto {http.reverse_proxy.upstream.scheme}
}

but I get the following error:

using adjacent Caddyfile
run: adapting config using caddyfile: parsing caddyfile tokens for 'reverse_proxy': Caddyfile:6 - Error during parsing: unrecognized subdirective {

Thanks

Unfortunately I don’t think that option is available in the Caddyfile yet.

For now, until we add it, you can comment out that one line from your Caddyfile, run caddy adapt --config Caddyfile --pretty and modify the JSON to add that property, then you can run Caddy with the JSON config for now.

I opened a quick PR to add it, should be available in the Caddyfile in v2.1 if not earlier.

You can also try it out right now by grabbing the build artifacts from here:

1 Like

Awesome! It works! Thank you

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