Skip to content

Commit f8c3ced

Browse files
committed
fix(template): $proxy_add_forwarded not defined in reverse_proxy.conf
1 parent 7fb8459 commit f8c3ced

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

template/block/reverse_proxy.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ map $http_upgrade $connection_upgrade {
2626
default upgrade;
2727
'' close;
2828
}
29+
map $remote_addr $proxy_forwarded_elem {
30+
# IPv4 addresses can be sent as-is
31+
~^[0-9.]+$ "for=$remote_addr";
32+
33+
# IPv6 addresses need to be bracketed and quoted
34+
~^[0-9A-Fa-f:.]+$ "for=\"[$remote_addr]\"";
35+
36+
# Unix domain socket names cannot be represented in RFC 7239 syntax
37+
default "for=unknown";
38+
}
39+
40+
map $http_forwarded $proxy_add_forwarded {
41+
# If the incoming Forwarded header is syntactically valid, append to it
42+
"~^(,[ \\t]*)*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*([ \\t]*,([ \\t]*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*)?)*$" "$http_forwarded, $proxy_forwarded_elem";
43+
44+
# Otherwise, replace it
45+
default "$proxy_forwarded_elem";
46+
}
2947
{{- end }}
3048
# Nginx UI Custom End
3149

0 commit comments

Comments
 (0)