使用阿里云的负载均衡(解决http到https的强转,解决https重定向http)
由于公司需要,需要在阿里云上部署负载均衡,研究了几天终于,在负载均衡上部署成功,废话不多说,开篇:
第一步:前端配置
1. 创建负载均衡
2.创建监听
四层(TCP/UDP协议)服务,负载均衡系统是基于源IP的会话保持。四层会话保持的最长时间是3600秒。
注意:会话保持开启(解决将同一客户端的会话请求转发给指定的一个后端服务器处理,这个如果不选会出现session问题)
七层(HTTP/HTTPS协议)服务,负载均衡系统是基于cookie的会话保持。植入cookie的会话保持的最长时间是86400秒(24小时)。
最终结果为
3.添加后端服务器
没有什么要说的。
第二步:后端服务器配置
1. 安装nginx ,这里就不多累述
2. 配置nginx
server {
listen 80;
server_name localhost:8080;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect http:// https://;
}
location = /50x.html {
root html;
}
}
server {
listen 81;
server_name localhost:8080;
rewrite ^(.*)$ https://$host$1permanent;(实现http到https强转的问题)
location / {
proxy_pass http://localhost:8080;
}
location = /50x.html {
root html;
}
}