Skip to content

Commit 3c23a2c

Browse files
committed
feat: listen on ipv6 sockets as well
Fixes #4391
1 parent 9feba9c commit 3c23a2c

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

etc/nginx/default.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
server {
22
{% if WEBLATE_BUILTIN_SSL %}
33
listen 4443 ssl;
4+
{% if ENABLE_IPV6 %}
5+
listen [::]:4443 ssl;
6+
{% endif %}
47

58
ssl_certificate /app/data/ssl/fullchain.pem;
69
ssl_certificate_key /app/data/ssl/privkey.pem;
@@ -18,6 +21,9 @@ server {
1821
ssl_dhparam /etc/nginx/ffdhe2048.pem;
1922
{% else %}
2023
listen 8080 default_server;
24+
{% if ENABLE_IPV6 %}
25+
listen [::]:8080 default_server;
26+
{% endif %}
2127
{% endif %}
2228
root /app/cache/static;
2329
client_max_body_size {{ CLIENT_MAX_BODY_SIZE }};
@@ -110,6 +116,9 @@ server {
110116
{% if WEBLATE_BUILTIN_SSL %}
111117
server {
112118
listen 8080 default_server;
119+
{% if ENABLE_IPV6 %}
120+
listen [::]:8080 default_server;
121+
{% endif %}
113122
server_tokens off;
114123
return 301 https://$host$request_uri;
115124
}

etc/nginx/generate-site.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
SITE_DOMAIN,
1515
ENABLE_HTTPS,
1616
GRANIAN_SOCKET,
17+
ENABLE_IPV6,
1718
) = sys.argv[1:]
1819

1920
WEBLATE_SITE_URL = "{}://{}".format(
@@ -47,6 +48,7 @@
4748
"WEBLATE_ANUBIS_URL": WEBLATE_ANUBIS_URL,
4849
"WEBLATE_SITE_URL": WEBLATE_SITE_URL,
4950
"GRANIAN_SOCKET": GRANIAN_SOCKET,
51+
"ENABLE_IPV6": ENABLE_IPV6,
5052
}
5153
)
5254
)

start

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,28 @@ find_nss_wrapper() {
9393
return 1
9494
}
9595

96+
ipv6_available() {
97+
WEBLATE_NGINX_IPV6_VALUE=$(printf '%s' "${WEBLATE_NGINX_IPV6:-auto}" | tr '[:upper:]' '[:lower:]')
98+
99+
if [ "$WEBLATE_NGINX_IPV6_VALUE" = "0" ] || [ "$WEBLATE_NGINX_IPV6_VALUE" = "false" ] || [ "$WEBLATE_NGINX_IPV6_VALUE" = "no" ] || [ "$WEBLATE_NGINX_IPV6_VALUE" = "off" ]; then
100+
return 1
101+
fi
102+
103+
if [ "$WEBLATE_NGINX_IPV6_VALUE" = "1" ] || [ "$WEBLATE_NGINX_IPV6_VALUE" = "true" ] || [ "$WEBLATE_NGINX_IPV6_VALUE" = "yes" ] || [ "$WEBLATE_NGINX_IPV6_VALUE" = "on" ]; then
104+
return 0
105+
fi
106+
107+
if [ ! -f /proc/net/if_inet6 ]; then
108+
return 1
109+
fi
110+
111+
if [ -r /proc/sys/net/ipv6/conf/all/disable_ipv6 ] && [ "$(cat /proc/sys/net/ipv6/conf/all/disable_ipv6)" = "1" ]; then
112+
return 1
113+
fi
114+
115+
return 0
116+
}
117+
96118
# Support OpenShift and other arbitrary-UID deployments without modifying
97119
# the system passwd database. Keep the legacy /etc/passwd append only as a
98120
# compatibility fallback for derived images that still make it writable.
@@ -315,6 +337,7 @@ if [ "$1" = "runserver" ]; then
315337
WEBLATE_REALIP="
316338
real_ip_header X-Forwarded-For;
317339
set_real_ip_from 0.0.0.0/0;
340+
set_real_ip_from ::/0;
318341
"
319342
;;
320343
*)
@@ -336,10 +359,27 @@ set_real_ip_from 0.0.0.0/0;
336359
# Make sure WEBLATE_ANUBIS_URL is set
337360
: "${WEBLATE_ANUBIS_URL:=""}"
338361
: "${WEBLATE_ENABLE_HTTPS:=""}"
362+
if ipv6_available; then
363+
WEBLATE_ENABLE_IPV6=1
364+
else
365+
WEBLATE_ENABLE_IPV6=
366+
fi
339367

340368
# Generate nginx configuration
341369
mkdir -p /tmp/nginx
342-
/app/venv/bin/python /etc/nginx/generate-site.py /etc/nginx "$WEBLATE_URL_PREFIX" "$WEBLATE_REALIP" "$CLIENT_MAX_BODY_SIZE" "$WEBLATE_BUILTIN_SSL" "$WEBLATE_ANUBIS_URL" "$WEBLATE_SITE_DOMAIN" "$WEBLATE_ENABLE_HTTPS" "$GRANIAN_SOCKET" > /tmp/nginx/weblate-site.conf
370+
/app/venv/bin/python \
371+
/etc/nginx/generate-site.py \
372+
/etc/nginx \
373+
"$WEBLATE_URL_PREFIX" \
374+
"$WEBLATE_REALIP" \
375+
"$CLIENT_MAX_BODY_SIZE" \
376+
"$WEBLATE_BUILTIN_SSL" \
377+
"$WEBLATE_ANUBIS_URL" \
378+
"$WEBLATE_SITE_DOMAIN" \
379+
"$WEBLATE_ENABLE_HTTPS" \
380+
"$GRANIAN_SOCKET" \
381+
"$WEBLATE_ENABLE_IPV6" \
382+
> /tmp/nginx/weblate-site.conf
343383

344384
# Calculate number of processes, at least 2, at most 4, depending on CPU cores
345385
if [ -z "$WEBLATE_WORKERS" ]; then

0 commit comments

Comments
 (0)