【问题标题】:http request to https request using haproxy使用haproxy的http请求到https请求
【发布时间】:2017-11-03 10:53:55
【问题描述】:

我有一种情况,我想使用 haproxy 将所有 http 请求重定向到 https 请求。假设我有一个服务器 x 安装了 haproxy 和一个服务器 y 运行实际服务(使用 ssl)。现在,我希望 haproxy 接受 http 请求并通过 https 将其转发到后端服务器。 有点像这样:

用户 haproxy 实际服务

到目前为止,我所做的是,前端接受端口 8080 中的 http 连接并将其发送到其默认后端,在后端我已预先添加“ssl verify none”。

使用这个,我可以从 http 加载页面,但是每当我提交请求(比如登录)时,响应都会在 http url 中出现,并且没有任何效果。

我根本不知道这是否可能。

如果我需要提供更多详细信息,请告诉我。

任何关于此的说明都会非常友好。

提前致谢。

【问题讨论】:

    标签: ssl haproxy


    【解决方案1】:

    你的配置是什么?

    你可能需要像这样指定端口

    server httpsserver 10.0.0.80:443 ssl verify none
    

    一个简单的 https 服务器:

    var express = require('express');
    var https = require('https');
    var fs = require('fs');
    var bodyParser = require('body-parser');
    var options = {
      key: fs.readFileSync('./client-key.pem'),
      cert: fs.readFileSync('./client-cert.pem')
    };
    var app = express();
    app.use(bodyParser.json());
    app.post('/post', function (req, res) {
      res.send(req.body);
    });
    https.createServer(options, app).listen(443);
    

    发布:

    curl -k -X POST https://127.0.0.1/post -d '{"a":"b"}' -H "Content-Type: application/json"                                                               
    {"a":"b"}
    

    HAProxy 配置:

    global
        debug
    defaults
        retries 3
        timeout client  300s
        timeout connect 300s
        timeout server  300s
    frontend web
        bind *:8080
        default_backend app
    backend app
        balance     roundrobin
        server httpsserver 127.0.0.1:443 ssl verify none
    

    针对 HAProxy 发布

    curl -k -X POST http://127.0.0.1:8080/post -d '{"a":"b"}' -H "Content-Type: application/json"                                                                 
    {"a":"b"}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 2013-11-02
      • 2017-11-05
      相关资源
      最近更新 更多