Docker-Swarm-Loadbalancer/templates/NginxTemplate.twig

89 lines
3 KiB
Twig
Raw Normal View History

2024-05-18 23:53:03 +00:00
upstream {{ backendName }} {
least_conn;
{% for backend in backends %}
server {{ backend }};
{% endfor %}
}
server {
{% if allowNonSSL %}
# Non-SSL Traffic is allowed
listen {{ portHttp }};
listen [::]:{{ portHttp }};
{% endif %}
# SSL Traffic is allowed
listen {{ portHttps }} ssl;
listen [::]:{{ portHttps }} ssl;
server_name {{ serverName }};
access_log /var/log/bouncer/{{ name }}.access.log;
error_log /var/log/bouncer/{{ name }}.error.log;
{% if certType == 'TEMPORARY_CERT' %}
ssl_certificate /certs/example.crt;
ssl_certificate_key /certs/example.key;
{% elseif certType == 'GLOBAL_CERT' %}
ssl_certificate /certs/global.crt;
ssl_certificate_key /certs/global.key;
{% elseif certType == 'CUSTOM_CERT' %}
ssl_certificate /etc/nginx/sites-enabled/{{ customCertFile }};
ssl_certificate_key /etc/nginx/sites-enabled/{{ customCertKeyFile }};
{% elseif certType == 'LETSENCRYPT_CERT' %}
ssl_certificate /etc/letsencrypt/live/{{ name }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ name }}/privkey.pem;
{% endif %}
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers HIGH:!aNULL:!MD5;
2022-06-15 09:34:07 +00:00
{% if allowLargePayloads %}
2023-02-07 14:26:44 +00:00
client_max_body_size 0;
{% endif %}
location / {
2024-01-25 10:41:42 +00:00
{% if hasHostOverride %}
proxy_set_header Host {{ hostOverride }};
2024-01-25 10:41:42 +00:00
{% else %}
proxy_set_header Host $host;
2024-01-25 10:41:42 +00:00
{% endif %}
2022-05-16 09:55:29 +00:00
# Server to send the request on to
2024-05-18 23:53:03 +00:00
proxy_pass "http://{{ backendName }}";
# Standard headers setting origin data
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
2023-01-09 14:57:00 +00:00
{% if hasAuth %}
# Http Basic Auth
auth_basic "closed site";
auth_basic_user_file sites-enabled/{{ authFile }};
2023-01-09 14:57:00 +00:00
{% endif %}
{% if allowWebsocketSupport %}
2022-05-16 09:55:29 +00:00
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_cache_bypass $http_upgrade;
proxy_buffering off;
proxy_set_header Origin "";
{% endif %}
2022-05-16 09:55:29 +00:00
2023-01-09 14:57:00 +00:00
{% if proxyTimeoutSeconds %}
# Proxy timeouts
proxy_read_timeout {{ proxyTimeoutSeconds }};
proxy_connect_timeout {{ proxyTimeoutSeconds }};
proxy_send_timeout {{ proxyTimeoutSeconds }};
2023-01-09 14:57:00 +00:00
{% endif %}
2024-01-25 11:37:06 +00:00
}
2022-06-18 23:23:47 +00:00
}
{% if not allowNonSSL %}
server {
# Redirect non-ssl to ssl
listen {{ portHttp }};
listen [::]:{{ portHttp }};
server_name {{ serverName }};
return 301 https://$host$request_uri;
}
2023-01-09 14:57:00 +00:00
{% endif %}