Nginx如何解决upstream存在https和http混合的情况
在负载均衡时候理想情况,所有的后端代理服务器都是http或者https的,很少遇到https和http混合的。如果遇到这种情况,解决方案有两种。
方案一:
统一所有后端的协议,全部为http或者全部为https。
upstream www_server{
server http1;
server http1;
}
server{
listen 443 ssl;
...
location / {
proxy_pass https://www_server;
proxy_redirect defatult;
}
方案二:本期再起一个反向代理服务,然后达到upstream协议里面所有的服务一致。
# https to http
server{
listen 8081;
...
location / {
proxy_pass https://https_server;
proxy_redirect defatult;
}
upstream www_server{
server http1;
server localhost:8081;
}
server{
listen 443 ssl;
...
location / {
proxy_pass http://www_server;
proxy_redirect defatult;
}