docker-gen
docker-gen copied to clipboard
Redirect to www not working
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
Ok, here is solutions:
- generate both certificates (www and non-www)
- create vhost example.com (non-www) and add redirect 301 to www version
- add VIRTUAL_HOST for both domain. (www and non-www)
- 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.