首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用ldirectord/LVS将HTTP重定向到HTTPS

用ldirectord/LVS将HTTP重定向到HTTPS
EN

Server Fault用户
提问于 2013-07-23 13:08:29
回答 1查看 1.6K关注 0票数 1

我们使用LVS进行负载平衡,并希望为http://example.com重定向到https://example.com

LVS可以在没有问题的情况下启用https,但是没有将http真正的服务器添加到池中(权重为0)。

LVS不遵循301重定向吗?如果没有,如何配置ldirectord将所有HTTP流量发送到HTTPS?

下面是nginx配置:

代码语言:javascript
复制
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看起来是这样的:

代码语言:javascript
复制
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端口”错误。

EN

回答 1

Server Fault用户

回答已采纳

发布于 2013-07-31 03:12:35

我让这件事变得更难了。

我修改了我的nginx.conf如下:

代码语言:javascript
复制
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中,因此匹配位置,搜索停止,并向lvs.htm提供200个响应代码。LVS将服务器添加到池中,当它被击中时,nginx将正确地用301重定向到https。

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/525624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档