Skip to content

Commit 3c12ced

Browse files
committed
allow enabling proxy protocol seperate for http and https
1 parent 154ed22 commit 3c12ced

5 files changed

Lines changed: 50 additions & 18 deletions

File tree

backend/templates/_common.conf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ server_name {{ server_names | join: " " }};
33
listen unix:/run/nginx.sock;
44

55
{% if env.DISABLE_HTTP == "false" %}
6-
listen {{ env.IPV4_BINDING }}:{{ env.HTTP_PORT }}{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
7-
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTP_PORT }}{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
6+
listen {{ env.IPV4_BINDING }}:{{ env.HTTP_PORT }}{% if env.LISTEN_PROXY_PROTOCOL_HTTP == "true" %} proxy_protocol{% endif %};
7+
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTP_PORT }}{% if env.LISTEN_PROXY_PROTOCOL_HTTP == "true" %} proxy_protocol{% endif %};{% endif %}
88
{% endif %}
99

1010
{% if certificate and certificate_id > 0 %}
11-
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} ssl{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
12-
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} ssl{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
11+
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} ssl{% if env.LISTEN_PROXY_PROTOCOL_HTTPS == "true" %} proxy_protocol{% endif %};
12+
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} ssl{% if env.LISTEN_PROXY_PROTOCOL_HTTPS == "true" %} proxy_protocol{% endif %};{% endif %}
1313

14-
{% if env.DISABLE_H3_QUIC == "false" and env.LISTEN_PROXY_PROTOCOL == "false" %}
14+
{% if env.DISABLE_H3_QUIC == "false" %}
1515
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} quic;
1616
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} quic;{% endif %}
1717
{% if npmplus_http3_support %}more_set_headers 'Alt-Svc: h3=":$alt_svc_port"; ma=86400';{% endif %}

backend/templates/default.conf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ server {
77
listen unix:/run/nginx.sock;
88

99
{% if env.DISABLE_HTTP == "false" %}
10-
listen {{ env.IPV4_BINDING }}:{{ env.HTTP_PORT }}{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
11-
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTP_PORT }}{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
10+
listen {{ env.IPV4_BINDING }}:{{ env.HTTP_PORT }}{% if env.LISTEN_PROXY_PROTOCOL_HTTP == "true" %} proxy_protocol{% endif %};
11+
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTP_PORT }}{% if env.LISTEN_PROXY_PROTOCOL_HTTP == "true" %} proxy_protocol{% endif %};{% endif %}
1212
{% endif %}
1313

14-
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} ssl{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
15-
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} ssl{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
14+
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} ssl{% if env.LISTEN_PROXY_PROTOCOL_HTTPS == "true" %} proxy_protocol{% endif %};
15+
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} ssl{% if env.LISTEN_PROXY_PROTOCOL_HTTPS == "true" %} proxy_protocol{% endif %};{% endif %}
1616

17-
{% if env.DISABLE_H3_QUIC == "false" and env.LISTEN_PROXY_PROTOCOL == "false" %}
17+
{% if env.DISABLE_H3_QUIC == "false" and env.LISTEN_PROXY_PROTOCOL_HTTPS == "false" %}
1818
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} quic;
1919
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} quic;{% endif %}
2020
more_set_headers 'Alt-Svc: h3=":$alt_svc_port"; ma=86400';
@@ -29,14 +29,14 @@ server {
2929
listen unix:/run/nginx.sock default_server;
3030

3131
{% if env.DISABLE_HTTP == "false" %}
32-
listen {{ env.IPV4_BINDING }}:{{ env.HTTP_PORT }} reuseport deferred so_keepalive=on default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
33-
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTP_PORT }} reuseport deferred so_keepalive=on default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
32+
listen {{ env.IPV4_BINDING }}:{{ env.HTTP_PORT }} reuseport deferred so_keepalive=on default_server{% if env.LISTEN_PROXY_PROTOCOL_HTTP == "true" %} proxy_protocol{% endif %};
33+
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTP_PORT }} reuseport deferred so_keepalive=on default_server{% if env.LISTEN_PROXY_PROTOCOL_HTTP == "true" %} proxy_protocol{% endif %};{% endif %}
3434
{% endif %}
3535

36-
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} ssl reuseport deferred so_keepalive=on default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
37-
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} ssl reuseport deferred so_keepalive=on default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
36+
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} ssl reuseport deferred so_keepalive=on default_server{% if env.LISTEN_PROXY_PROTOCOL_HTTPS == "true" %} proxy_protocol{% endif %};
37+
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} ssl reuseport deferred so_keepalive=on default_server{% if env.LISTEN_PROXY_PROTOCOL_HTTPS == "true" %} proxy_protocol{% endif %};{% endif %}
3838

39-
{% if env.DISABLE_H3_QUIC == "false" and env.LISTEN_PROXY_PROTOCOL == "false" %}
39+
{% if env.DISABLE_H3_QUIC == "false" %}
4040
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} quic reuseport default_server;
4141
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} quic reuseport default_server;{% endif %}
4242
more_set_headers 'Alt-Svc: h3=":$alt_svc_port"; ma=86400';

compose.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ services:
5656
# - "HTTP_PORT=8080" # tcp port to use for http traffic, changing this may break certbot http challenge, default 80
5757
# - "HTTPS_PORT=8443" # udp and tcp port to use for https traffic, changing this may break certbot http challenge, default 443
5858
# - "DISABLE_HTTP=true" # prevents nginx from listening on port 80, default false
59-
# - "LISTEN_PROXY_PROTOCOL=true" # should listeners of http(s) hosts (proxy/redirect/dead and default) use proxy protocol instead of http(s)? default false, overrides DISABLE_H3_QUIC to true
59+
# - "LISTEN_PROXY_PROTOCOL=true" # should listeners of http(s) hosts (proxy/redirect/dead and default) use proxy protocol instead of http(s)? default false, overrides DISABLE_H3_QUIC, LISTEN_PROXY_PROTOCOL_HTTP and LISTEN_PROXY_PROTOCOL_HTTPS to true
60+
# - "LISTEN_PROXY_PROTOCOL_HTTP=true" # should listeners of http hosts (proxy/redirect/dead and default) use proxy protocol instead of http? default false
61+
# - "LISTEN_PROXY_PROTOCOL_HTTPS=true" # should listeners of https hosts (proxy/redirect/dead and default) use proxy protocol instead of https? default false, overrides DISABLE_H3_QUIC to true
6062
# - "DISABLE_H3_QUIC=true" # prevents nginx from listening on port 443 udp for default host and all your hosts, this will fully disable HTTP/3 and QUIC, even if you enable it inside the UI, not recommended, default false
61-
# - "NGINX_QUIC_BPF=true" # enables nginx's quic_bpf (https://nginx.org/en/docs/http/ngx_http_v3_module.html#quic_bpf), you must also add caps to the NPMplus container (see cap_add of this compose file) to use this, recommended, default false
63+
# - "NGINX_QUIC_BPF=true" # enables nginx's quic_bpf (https://nginx.org/en/docs/http/ngx_http_v3_module.html#quic_bpf), you must also add caps to the NPMplus container (see cap_add of this compose file) to use this, default false
6264
# - "NGINX_LOG_NOT_FOUND=true" # Log 404 errors to the docker logs, unrelated to access logs, default false
6365
# - "NGINX_WORKER_PROCESSES=8" # value of worker_processes, default and recommended: auto
6466
# - "NGINX_WORKER_CONNECTIONS=1024" # value of worker_connections, default: 512

rootfs/usr/local/bin/envs.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export HTTP_PORT="${HTTP_PORT:-80}"
9999
export HTTPS_PORT="${HTTPS_PORT:-443}"
100100
export DISABLE_HTTP="${DISABLE_HTTP:-false}"
101101
export LISTEN_PROXY_PROTOCOL="${LISTEN_PROXY_PROTOCOL:-false}"
102+
export LISTEN_PROXY_PROTOCOL_HTTP="${LISTEN_PROXY_PROTOCOL_HTTP:-false}"
103+
export LISTEN_PROXY_PROTOCOL_HTTPS="${LISTEN_PROXY_PROTOCOL_HTTPS:-false}"
102104
export DISABLE_H3_QUIC="${DISABLE_H3_QUIC:-false}"
103105
export NGINX_QUIC_BPF="${NGINX_QUIC_BPF:-false}"
104106
export NGINX_LOG_NOT_FOUND="${NGINX_LOG_NOT_FOUND:-false}"
@@ -439,6 +441,16 @@ if ! echo "$LISTEN_PROXY_PROTOCOL" | grep -q "^true$\|^false$"; then
439441
sleep inf
440442
fi
441443

444+
if ! echo "$LISTEN_PROXY_PROTOCOL_HTTP" | grep -q "^true$\|^false$"; then
445+
echo "LISTEN_PROXY_PROTOCOL_HTTP needs to be true or false."
446+
sleep inf
447+
fi
448+
449+
if ! echo "$LISTEN_PROXY_PROTOCOL_HTTPS" | grep -q "^true$\|^false$"; then
450+
echo "LISTEN_PROXY_PROTOCOL_HTTPS needs to be true or false."
451+
sleep inf
452+
fi
453+
442454
if ! echo "$DISABLE_H3_QUIC" | grep -q "^true$\|^false$"; then
443455
echo "DISABLE_H3_QUIC needs to be true or false."
444456
sleep inf
@@ -720,18 +732,36 @@ if [ "$ACME_MUST_STAPLE" = "true" ] && [ "$ACME_OCSP_STAPLING" = "false" ]; then
720732
export ACME_OCSP_STAPLING="true"
721733
echo "setting ACME_OCSP_STAPLING to true, since ACME_MUST_STAPLE is set to true."
722734
fi
735+
723736
if [ "$LISTEN_PROXY_PROTOCOL" = "true" ] && [ "$DISABLE_H3_QUIC" = "false" ]; then
724737
export DISABLE_H3_QUIC="true"
725738
echo "setting DISABLE_H3_QUIC to true, since LISTEN_PROXY_PROTOCOL is set to true."
726739
fi
740+
741+
if [ "$LISTEN_PROXY_PROTOCOL" = "true" ] && [ "$LISTEN_PROXY_PROTOCOL_HTTP" = "false" ]; then
742+
export LISTEN_PROXY_PROTOCOL_HTTP="true"
743+
echo "setting LISTEN_PROXY_PROTOCOL_HTTP to true, since LISTEN_PROXY_PROTOCOL is set to true."
744+
fi
745+
746+
if [ "$LISTEN_PROXY_PROTOCOL" = "true" ] && [ "$LISTEN_PROXY_PROTOCOL_HTTPS" = "false" ]; then
747+
export LISTEN_PROXY_PROTOCOL_HTTPS="true"
748+
echo "setting LISTEN_PROXY_PROTOCOL_HTTPS to true, since LISTEN_PROXY_PROTOCOL is set to true."
749+
fi
750+
751+
if [ "$LISTEN_PROXY_PROTOCOL_HTTP" != "$LISTEN_PROXY_PROTOCOL_HTTPS" ]; then
752+
echo "LISTEN_PROXY_PROTOCOL_HTTP and LISTEN_PROXY_PROTOCOL_HTTPS are different, please note that only the proxy protocol realip header will be read, but not the X-Forwarded-For http header."
753+
fi
754+
727755
if [ "$NGINX_FORCE_X25519MLKEM768" = "true" ] && [ "$NGINX_DISABLE_TLS12" = "false" ]; then
728756
export NGINX_DISABLE_TLS12="true"
729757
echo "setting NGINX_DISABLE_TLS12 to true, since NGINX_FORCE_X25519MLKEM768 is set to true."
730758
fi
759+
731760
if [ "$NGINX_FORCE_X25519MLKEM768" = "true" ] && [ "$NGINX_TRUST_SECPR1" = "true" ]; then
732761
export NGINX_TRUST_SECPR1="false"
733762
echo "setting NGINX_TRUST_SECPR1 to false, since NGINX_FORCE_X25519MLKEM768 is set to true."
734763
fi
764+
735765
if [ "$GOA" = "true" ] && [ "$LOGROTATE" = "false" ]; then
736766
export LOGROTATE="true"
737767
echo "setting LOGROTATE to true, since GOA is set to true."

rootfs/usr/local/bin/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ if [ "$GOA" = "true" ]; then
388388
cp -van /usr/local/nginx/conf/conf.d/goaccess.conf.disabled /usr/local/nginx/conf/conf.d/goaccess.conf
389389
fi
390390

391-
if [ "$LISTEN_PROXY_PROTOCOL" = "true" ]; then
391+
if [ "$LISTEN_PROXY_PROTOCOL_HTTP" = "true" ] || [ "$LISTEN_PROXY_PROTOCOL_HTTPS" = "true" ]; then
392392
sed -i "s|real_ip_header.*|real_ip_header proxy_protocol;|g" /usr/local/nginx/conf/nginx.conf
393393
fi
394394
if [ "$NGINX_QUIC_BPF" = "true" ]; then

0 commit comments

Comments
 (0)