ipv6 migration

This commit is contained in:
2024-06-21 15:04:58 -04:00
parent 1f4769fdbe
commit 45c58aeba7
25 changed files with 357 additions and 62 deletions

View File

@@ -27,10 +27,12 @@ events {
}
stream {
log_format basic '| Remote Addr: $remote_addr:$server_port | SSL Preread: $ssl_preread_server_name | Forward: $map_forward_ip$upstream_port | Upstream Addr: $upstream_addr | $time_local | $protocol | $status | $bytes_sent | $bytes_received | $session_time |';
log_format basic '| Remote Addr: $remote_addr:$server_port | SSL Preread: $ssl_preread_server_name | Forward: $map_forward$upstream_port | Upstream Addr: $upstream_addr | $time_local | $protocol | $status | $bytes_sent | $bytes_received | $session_time |';
include /etc/nginx/stream.d/*.conf;
# Map all SSL parsed server names to hosts
map $ssl_preread_server_name $map_forward_ip {
map $ssl_preread_server_name $map_forward {
# Empty ssl preread gets forwarded to internal http server
"" "unix:/var/lib/nginx/tmp/nginx_http.sock";
@@ -46,7 +48,7 @@ stream {
# Since traffic being forwarded to the unix socket doesn't need a port we'll create
# a map here to enforce that case.
map $map_forward_ip $upstream_port {
map $map_forward $upstream_port {
{{ defaults.forward_ip }} ":443";
"unix:/var/lib/nginx/tmp/nginx_http.sock" "";
@@ -73,18 +75,16 @@ stream {
listen [::]:{{ port }};
{% endfor %}
proxy_pass $map_forward_ip$upstream_port;
proxy_pass $map_forward$upstream_port;
ssl_preread on;
proxy_socket_keepalive on;
}
include /etc/nginx/stream.d/*.conf;
}
http {
log_format basic '| Proxy Proto Addr: $proxy_protocol_addr | Remote Addr: $remote_addr:$server_port | Host: $host | Forward: $map_forward_ip$server_port | Referer: $http_referer | $request | $time_local | $status |';
log_format basic '| Proxy Proto Addr: $proxy_protocol_addr | Internal: $external_addr | Remote Addr: $remote_addr:$server_port | Host: $host | Forward: $map_forward$server_port | Referer: $http_referer | $request | $time_local | $status |';
map $host $map_forward_ip {
map $host $map_forward {
"" "unix:/var/lib/nginx/tmp/nginx_http.sock";
# We don't want to forward traffic we're terminating
@@ -105,8 +105,8 @@ http {
location / {
# If we have an external forward IP, forward traffic
if ($map_forward_ip != "unix:/var/lib/nginx/tmp/nginx_http.sock") {
proxy_pass $map_forward_ip:80;
if ($map_forward != "unix:/var/lib/nginx/tmp/nginx_http.sock") {
proxy_pass $map_forward:80;
}
# Else redirect if the scheme is http
if ($scheme = "http") {
@@ -115,6 +115,16 @@ http {
}
}
map $proxy_protocol_addr $external_addr {
default 1;
{% for ip in internal_ipv4_regex %}
~{{ ip }} 0;
{% endfor %}
{% for ip in internal_ipv6_regex %}
~{{ ip }} 0;
{% endfor %}
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;