2022-05-27 03:32:25 +00:00
|
|
|
server {
|
2022-08-27 22:56:12 +00:00
|
|
|
listen 80;
|
|
|
|
listen [::]:80;
|
|
|
|
server_name {{ item.domain }};
|
|
|
|
return 301 https://{{ item.domain }}$request_uri;
|
2022-05-27 03:32:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-22 04:19:56 +00:00
|
|
|
server {
|
2022-08-27 22:56:12 +00:00
|
|
|
listen 443 ssl http2;
|
|
|
|
listen [::]:443 ssl http2;
|
2022-05-22 04:19:56 +00:00
|
|
|
server_name {{ item.domain }};
|
|
|
|
access_log /var/log/nginx/{{ item.domain }}.log main;
|
2022-05-24 02:33:17 +00:00
|
|
|
{% if proxy.production is defined and proxy.production and proxy.dns_cloudflare.wildcard_domains is defined and item.tls.cert is not defined %}
|
|
|
|
{% for wildcard in proxy.dns_cloudflare.wildcard_domains %}
|
|
|
|
{% set domain_regex = '^\*\.' + wildcard + '$' %}
|
|
|
|
{% if item.domain | regex_search(wildcard) %}
|
|
|
|
ssl_certificate /etc/letsencrypt/live/{{ wildcard }}/fullchain.pem;
|
|
|
|
ssl_certificate_key /etc/letsencrypt/live/{{ wildcard }}/privkey.pem;
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
{% elif proxy.production is defined and proxy.production and item.tls.cert is not defined %}
|
2022-05-23 07:32:56 +00:00
|
|
|
ssl_certificate /etc/letsencrypt/live/{{ item.domain }}/fullchain.pem;
|
|
|
|
ssl_certificate_key /etc/letsencrypt/live/{{ item.domain }}/privkey.pem;
|
2022-05-24 02:33:17 +00:00
|
|
|
{% elif proxy.production is defined and proxy.production and item.tls.cert is defined %}
|
2022-05-23 07:32:56 +00:00
|
|
|
ssl_certificate {{ item.tls.cert }};
|
|
|
|
ssl_certificate_key {{ item.tls.key }};
|
|
|
|
{% else %}
|
2022-05-22 04:19:56 +00:00
|
|
|
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
|
|
|
|
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
|
2022-08-19 05:27:55 +00:00
|
|
|
{% endif %}
|
2022-08-27 22:56:12 +00:00
|
|
|
{% if item.hsts is defined %}
|
|
|
|
add_header Strict-Transport-Security "max-age={{ item.hsts }}" always;
|
|
|
|
{% endif %}
|
2022-08-19 05:27:55 +00:00
|
|
|
{% if item.client_max_body_size is defined %}
|
|
|
|
client_max_body_size {{ item.client_max_body_size }};
|
2022-05-22 04:19:56 +00:00
|
|
|
{% endif %}
|
|
|
|
location / {
|
2022-08-17 05:15:15 +00:00
|
|
|
{% if item.restrict is defined and item.restrict %}
|
|
|
|
auth_basic "{{ item.restrict_name | default('Restricted Access') }}";
|
|
|
|
auth_basic_user_file {{ item.restrict_file | default('/etc/nginx/.htpasswd') }};
|
2022-08-19 04:51:05 +00:00
|
|
|
proxy_set_header Authorization "";
|
2022-08-17 05:15:15 +00:00
|
|
|
{% endif %}
|
2022-05-22 04:19:56 +00:00
|
|
|
proxy_set_header Host $host;
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
2022-05-28 02:33:35 +00:00
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
2022-05-22 04:19:56 +00:00
|
|
|
proxy_pass {{ item.proxy_pass }};
|
2022-08-17 05:15:15 +00:00
|
|
|
{% if item.proxy_ssl_verify is defined and item.proxy_ssl_verify is false %}
|
|
|
|
proxy_ssl_verify off;
|
2022-12-06 05:15:10 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if item.websockets is defined and item.websockets %}
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_set_header Connection $http_connection;
|
|
|
|
proxy_set_header Origin http://$host;
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
2022-08-17 05:15:15 +00:00
|
|
|
{% endif %}
|
2022-05-22 04:19:56 +00:00
|
|
|
}
|
|
|
|
}
|