Skip to content

Commit a567d5d

Browse files
committed
[Nginx] Add support for trusted proxies via env var
1 parent 4ac541f commit a567d5d

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

data/Dockerfiles/nginx/bootstrap.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ def nginx_conf(env, template_vars):
4343
def prepare_template_vars():
4444
ipv4_network = os.getenv("IPV4_NETWORK", "172.22.1")
4545
additional_server_names = os.getenv("ADDITIONAL_SERVER_NAMES", "")
46+
trusted_proxies = os.getenv("TRUSTED_PROXIES", "")
4647

4748
template_vars = {
4849
'IPV4_NETWORK': ipv4_network,
49-
'TRUSTED_NETWORK': os.getenv("TRUSTED_NETWORK", False),
50+
'TRUSTED_PROXIES': [item.strip() for item in trusted_proxies.split(",") if item.strip()],
5051
'SKIP_RSPAMD': os.getenv("SKIP_RSPAMD", "n").lower() in ("y", "yes"),
5152
'SKIP_SOGO': os.getenv("SKIP_SOGO", "n").lower() in ("y", "yes"),
5253
'NGINX_USE_PROXY_PROTOCOL': os.getenv("NGINX_USE_PROXY_PROTOCOL", "n").lower() in ("y", "yes"),

data/conf/nginx/templates/sites-default.conf.j2

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ set_real_ip_from 10.0.0.0/8;
5252
set_real_ip_from 172.16.0.0/12;
5353
set_real_ip_from 192.168.0.0/16;
5454
set_real_ip_from fc00::/7;
55-
{% if not TRUSTED_NETWORK %}
55+
{% for TRUSTED_PROXY in TRUSTED_PROXIES %}
56+
set_real_ip_from {{ TRUSTED_PROXY }};
57+
{% endfor %}
58+
{% if not NGINX_USE_PROXY_PROTOCOL %}
5659
real_ip_header X-Forwarded-For;
5760
{% else %}
58-
set_real_ip_from {{ TRUSTED_NETWORK }};
5961
real_ip_header proxy_protocol;
6062
{% endif %}
6163
real_ip_recursive on;

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ services:
376376
- php-fpm-mailcow
377377
- sogo-mailcow
378378
- rspamd-mailcow
379-
image: mailcow/nginx:1.02
379+
image: mailcow/nginx:1.03
380380
dns:
381381
- ${IPV4_NETWORK:-172.22.1}.254
382382
environment:
@@ -394,6 +394,8 @@ services:
394394
- RSPAMDHOST=${RSPAMDHOST:-}
395395
- REDISHOST=${REDISHOST:-}
396396
- IPV4_NETWORK=${IPV4_NETWORK:-172.22.1}
397+
- NGINX_USE_PROXY_PROTOCOL=${NGINX_USE_PROXY_PROTOCOL:-n}
398+
- TRUSTED_PROXIES=${TRUSTED_PROXIES:-}
397399
volumes:
398400
- ./data/web:/web:ro,z
399401
- ./data/conf/rspamd/dynmaps:/dynmaps:ro,z

0 commit comments

Comments
 (0)