Skip to content

Commit 12ac783

Browse files
authored
Redirect directly to https canonical domain (#889)
http://www.xyz.com -> http://xyz.com -> https://xyz.com becomes simply http://www.xyz.com -> https://xyz.com Also move return directive back into location block so that it will run only if acme challenge location is not matched. Otherwise Let's Encrypt validation in this server block would fail due to 301 redirect.
1 parent 82926f6 commit 12ac783

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

roles/wordpress-setup/templates/wordpress-site.conf.j2

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ server {
196196
server {
197197
listen [::]:80;
198198
listen 80;
199-
server_name {{ site_hosts | union(multisite_subdomains_wildcards) | join(' ') }};
199+
server_name {{ site_hosts_canonical | union(multisite_subdomains_wildcards) | join(' ') }};
200200

201201
{{ self.acme_challenge() -}}
202202

@@ -216,8 +216,12 @@ server {
216216
{% endif %}
217217
{% for host in item.value.site_hosts if host.redirects | default([]) %}
218218
server {
219-
listen {{ ssl_enabled | ternary('[::]:443 ssl http2', '[::]:80') }};
220-
listen {{ ssl_enabled | ternary('443 ssl http2', '80') }};
219+
{% if ssl_enabled -%}
220+
listen [::]:443 ssl http2;
221+
listen 443 ssl http2;
222+
{% endif -%}
223+
listen [::]:80;
224+
listen 80;
221225
server_name {{ host.redirects | join(' ') }};
222226

223227
{{ self.https() -}}
@@ -226,7 +230,9 @@ server {
226230

227231
{{ self.includes_d() -}}
228232

229-
return 301 $scheme://{{ host.canonical }}$request_uri;
233+
location / {
234+
return 301 {{ ssl_enabled | ternary('https', 'http') }}://{{ host.canonical }}$request_uri;
235+
}
230236
}
231237
{% endfor %}
232238
{% endblock %}

0 commit comments

Comments
 (0)