I have the following nginx configuration for redirecting traffic to one of two proxies. One is charles running locally on port 8889 and the other is an mitmproxy docker instance running on the exposed port 8080. I map the traffic to either proxy based on the server_name using the $ssl_preread_server_name map as below. When I curl through the nginx server on port 9991 with www.google.com it correctly goes through the charles proxy however when I attempt to ping the kong server, https://kong:8445 it doesn't get redirected through the mitmproxy. The servername kong, oddly gets resolved correctly to its IP, 172.17.0.4, which then attempts to redirect through charles? Can anyone see what I'm doing wrong here?
map $ssl_preread_server_name $upstream {
hostnames;
www.google.com charles;
kong mitmproxy;
172.17.0.4 mitmproxy;
default charles;
}
#user nobody;
worker_processes 1;
#pid /usr/local/var/log/nginx.pid;
events {
worker_connections 1024;
}
stream {
log_format custom_log_format '$remote_addr - [$time_local] ';
# '$request_uri $status $body_bytes_sent '
# '"$http_referer" "$http_user_agent" "$gzip_ratio"';
access_log /usr/local/var/log/nginx/access.log custom_log_format;
error_log /usr/local/var/log/nginx/error.log;
upstream mitmproxy {
server 192.168.0.19:8080;
}
upstream charles {
server 192.168.0.19:8889;
}
map $ssl_preread_server_name $upstream {
hostnames;
www.google.com charles;
kong mitmproxy;
172.17.0.4 mitmproxy;
default charles;
}
server {
listen 9991;
listen [::]:9991;
ssl_preread on;
proxy_pass $upstream;
}
}