Nginx使用tcp协议通过域名反向代理多个不同的https后端
后端有多个https服务,不同域名请求要把流量打到同的后端服务。
前提条件:每个服务的https证书需要包含域名信息。
#!/bin/bash
docker run -d --name nginx \
-v $(pwd)/nginx.conf:/etc/nginx/nginx.conf \
-p 443:443 \
nginx:1.22.0-alpine
配置文件
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
stream {
map $ssl_preread_server_name $name {
www.xwjh.run www;
xwjh.run xwjh;
}
upstream www{
server 43.138.130.70:443;
}
upstream xwjh{
server 43.138.130.70:443;
}
upstream https_default_backend {
server 127.0.0.1:443;
}
server {
listen 443;
proxy_pass $name;
ssl_preread on;
}
}
参考
https://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html