我的目标是在启用HTTPS的情况下,将所有来自parent_server.com的请求负载均衡到child_server1.com和child_server2.com。这是我当前的负载均衡器配置:
upstream childServers {
server child_server1.com:443;
server child_server2.com:443;
}
server {
server_name parent_server.com
location / {
#proxy_pass https://childServers;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
// certbot information
}
server {
if ($host = parent_server.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name parent_server.com;
return 404; # managed by Certbot
}
这是我的子服务器Nginx块,它位于另一台服务器上。
server {
server_name child_server1.com;
location / {
#proxy_pass http://localhost:9000;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
// certbot information
}
server {
if ($host = child_server1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name child_server1.com;
return 404; # managed by Certbot
}
不幸的是,这不起作用,因为来自负载平衡器的请求会将主机作为“ parent_server.com”。我可以使用的一种解决方法是侦听子级服务器中的所有请求,而不是仅监听child_server1.com。这是正确的方法吗?还是还有其他正确的方法?