dataset/seed/nginx-reverse-proxy/templates/revprox-nginx.conf

104 lines
3.8 KiB
Text
Raw Permalink Normal View History

2023-01-17 21:43:32 +01:00
#RISOTTO: do not compare
2023-06-23 08:12:05 +02:00
{% macro add_location(rp_domainname, family, loc_idx, location, http) %}
location {{ location }} {
proxy_pass {{ rp_domainname['revprox_url_' + family] }};
{% if loc_idx in rp_domainname['revprox_is_websocket_' + family] and rp_domainname['revprox_is_websocket_' + family][loc_idx] %}
2022-04-08 18:52:43 +02:00
proxy_http_version 1.1;
2022-03-11 19:55:02 +01:00
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
2023-06-23 08:12:05 +02:00
{% else %}
2022-03-08 19:42:28 +01:00
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Destination $dest;
2023-06-23 08:12:05 +02:00
{% endif %}
{%if not http %}
proxy_ssl_trusted_certificate {{ tls_ca_directory }}/InternalReverseProxy.crt;
2022-03-08 19:42:28 +01:00
proxy_ssl_verify on;
proxy_ssl_verify_depth 2;
proxy_ssl_session_reuse on;
2023-02-14 14:24:16 +01:00
# SNI support
proxy_ssl_server_name on;
2023-06-23 08:12:05 +02:00
{% endif %}
{% set maxbody = rp_domainname['revprox_max_body_size_' + family] %}
{% if maxbody %}
client_max_body_size {{ maxbody }};
{% endif %}
2022-03-08 19:42:28 +01:00
set $dest $http_destination;
index error.html;
root /var/www/html;
}
2022-03-11 18:41:49 +01:00
# If user missing '/'
2023-06-23 08:12:05 +02:00
{% if location != '/' and location.endswith('/') %}
location {{ location[:-1] }} {
rewrite ^({{ location[:-1] }})$ $1/ permanent;
2022-03-08 19:42:28 +01:00
}
2023-06-23 08:12:05 +02:00
{% endif %}
{% endmacro %}
{% macro add_locations(domainname, http) %}
{% for remote in nginx.remotes %}
{% set family = remote|normalize_family %}
{% set revprox = nginx['reverse_proxy_for_' + family]['reverse_proxy_' + family] %}
{% for rp_domainname in revprox['revprox_domainnames_' + family] %}
{% if rp_domainname['revprox_http_' + family] == http and (rp_domainname|string == 'None' or domainname == rp_domainname|string) %}
{% for location in rp_domainname['revprox_location_' + family] %}
{{ add_location(rp_domainname, family, loop.index - 1, location, http) }}
{% endfor %}
{% endif %}
{% endfor %}
{% endfor %}
{% endmacro %}
2023-02-14 14:24:16 +01:00
# Add default HTTP entries if useful
# Not for HTTPs because there is no certificate
2023-06-23 08:12:05 +02:00
{% set default_http_location = [] %}
{% for remote in nginx.remotes %}
{% set family = remote|normalize_family %}
{% for rp_domainname in nginx['reverse_proxy_for_' + family]['reverse_proxy_' + family]['revprox_domainnames_' + family] %}
{% if rp_domainname|string == 'None' and rp_domainname['revprox_http_' + family] %}
{{ default_http_location.append((family, rp_domainname)) }}
{% endif %}
{% endfor %}
{% endfor %}
{% if default_http_location %}
2023-02-14 14:24:16 +01:00
server {
listen 80;
server_name _ default;
2023-06-23 08:12:05 +02:00
{% for family, rp_domainname in default_http_location %}
{% for location in rp_domainname['revprox_location_' + family] %}
{{ add_location(rp_domainname, family, loop.index - 1, location, True) }}
{% endfor %}
{% endfor %}
2023-02-14 14:24:16 +01:00
break;
}
2023-06-23 08:12:05 +02:00
{% endif %}
{% for domainname in nginx.revprox_domainnames %}
# Configuration HTTP {{ domainname }}
2023-02-14 14:24:16 +01:00
server {
listen 80;
2023-06-23 08:12:05 +02:00
server_name {{ domainname }};
{{ add_locations(domainname, True) }}
2023-02-14 14:24:16 +01:00
location / {
2023-06-23 08:12:05 +02:00
return 301 https://{{ domainname }}$request_uri;
2023-02-14 14:24:16 +01:00
}
}
2023-06-23 08:12:05 +02:00
# Configuration HTTPS {{ domainname }}
2023-02-14 14:24:16 +01:00
server {
listen 443 ssl http2;
2023-06-23 08:12:05 +02:00
ssl_certificate {{ tls_cert_directory }}/{{ domainname }}.crt;
ssl_certificate_key {{ tls_key_directory }}/{{ domainname }}.key;
server_name {{ domainname }};
2023-02-14 14:24:16 +01:00
error_page 403 404 502 503 504 /error.html;
location = /error.html {
root /var/www/html;
}
2023-06-23 08:12:05 +02:00
{{ add_locations(domainname, False) }}
2022-03-08 19:42:28 +01:00
}
2022-08-18 10:19:43 +02:00
2023-06-23 08:12:05 +02:00
{% endfor %}