automation/deployer/roles/build/templates/drupal/nginx.host.j2

57 lines
1.3 KiB
Text
Raw Normal View History

# Generated by ansible for site {{ site.url }}
# At {{ site.subnet_site_ip }} on {{ site.subnet_cidr_address }}
2020-04-28 09:59:52 +00:00
server {
listen 80;
listen [::]:80;
server_name {{ site.url }} www.{{ site.url }};
2020-04-28 09:59:52 +00:00
# Let's Encrypt
include snippets/letsencrypt.conf;
location / {
{% if site.redirect_to_www %}
return 301 https://www.{{ site.url }}$request_uri;
2020-04-28 09:59:52 +00:00
{% else %}
return 301 https://{{ site.url }}$request_uri;
2020-04-28 09:59:52 +00:00
{% endif %}
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name {{ site.url }} www.{{ site.url }};
2020-04-28 09:59:52 +00:00
access_log /var/log/nginx/{{ site.slug }}-access.log;
2020-04-28 09:59:52 +00:00
error_log /var/log/nginx/error.log;
{% if site.redirect_to_www %}
2020-04-28 09:59:52 +00:00
# Redirect non-www to www
if ($host = {{ site.url }}) {
rewrite ^ https://www.{{ site.url }}$request_uri permanent;
2020-04-28 09:59:52 +00:00
}
{% else %}
# Redirect www to non-www
if ($host = www.{{ site.url }}) {
rewrite ^ https://{{ site.url }}$request_uri permanent;
2020-04-28 09:59:52 +00:00
}
{% endif %}
# Let's Encrypt
include snippets/letsencrypt.conf;
include snippets/ssl-params.conf;
ssl_certificate /etc/letsencrypt/live/{{ site.url }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ site.url }}/privkey.pem;
2020-04-28 09:59:52 +00:00
include snippets/header-params_server.conf;
location / {
include snippets/header-params_location.conf;
proxy_pass http://{{ site.subnet_site_ip }}:80;
2020-04-28 09:59:52 +00:00
}
}