docker-gen icon indicating copy to clipboard operation
docker-gen copied to clipboard

Redirect to www not working

Open petrck opened this issue 9 years ago • 1 comments

Hello, I need to redirect from https://example.com to https://www.example.com. From non SSL it works well. But I don't know, how can I do redirect from https. Is it possible? I'm using template from nginx-proxy (in attachment). For no ssl I use vhost with filename example.com.

Thank you very much. nginx.tmpl.zip

petrck avatar Feb 05 '17 20:02 petrck

Ok, here is solutions:

  1. generate both certificates (www and non-www)
  2. create vhost example.com (non-www) and add redirect 301 to www version
  3. add VIRTUAL_HOST for both domain. (www and non-www)
  4. unsure, that conf.d/default has include directive and include your host to non www version (check in running container with docker exec ...)

something like this:

        {{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
	include {{ printf "/etc/nginx/vhost.d/%s" $host }};
	{{ else if (exists "/etc/nginx/vhost.d/default") }}
	include /etc/nginx/vhost.d/default;
	{{ end }}

It's all. Works well.

petrck avatar Feb 06 '17 11:02 petrck