使用ldirectord / LVS将HTTPredirect到HTTPS

我们使用LVS进行负载均衡,并希望将http://example.com的301redirect到https://example.com

LVS启用https没有问题,但http真实服务器没有被添加到池(权重为0)。

LVS是否不遵循301redirect? 如果没有,我如何configurationldirectord发送所有HTTPstream量到HTTPS?

这里是nginxconfiguration:

server { listen 80; server_name example.com; return 301 https://example.com$request_uri; } server { listen 443; ssl on; ssl_certificate server.crt; ssl_certificate_key server.key; server_name example.com; # more here } 

和ldirectord.cf看起来像这样:

 virtual=VIP:80 fallback=127.0.0.1:80 real=10.0.0.7:80 masq 5 real=10.0.0.8:80 masq 5 service=http request="lvs.htm" receive="lvs" virtualhost=example.com scheduler=wlc protocol=tcp checktype=negotiate virtual=VIP:443 fallback=127.0.0.1:443 real=10.0.0.7:443 masq 5 real=10.0.0.8:443 masq 5 service=https request="lvs.htm" receive="lvs" virtualhost=example.com scheduler=wlc protocol=tcp checktype=negotiate 

我也尝试设置我的VIP端口80和我的RIP端口443,导致服务器被添加到池,但nginx然后返回400“纯HTTP请求被发送到HTTPS端口”错误。

我做得比想要的要难。

我修改了我的nginx.conf,如下所示:

 server { listen 80; server_name example.com; root /var/www; location = /lvs.htm { #do nothing } location / { return 301 https://example.com$request_uri; } } 

lvs.htm驻留在/ var / www中,因此位置匹配,search停止,lvs.htm被提供200响应代码。 LVS将服务器添加到池中,当它被命中时,nginx会正确地redirect到使用301的https。