0
votes

I have a situation where I want to redirect all the http requests to https request using haproxy. Let say, I have a server x where haproxy is installed and a server y where actual services are running (using ssl). Now, I want that the haproxy to accept http requests and forward it to the backend server via https. Kinda like this:

user <--(http)--> haproxy <--(https)--> actual service

what I have done so far is, frontend accepts http connection in port 8080 and it sends to its default-backend, in backend I have prepended "ssl verify none".

Using this, I could load the page from http but whenever I am submitting a request (say login), response is coming in http url and nothing works.

I don't know whether at all if this is possible.

Let me know if I need to provide more details on this.

Any light on this would be very kind.

Thanks in advance.

1

1 Answers

4
votes

What is your config?

You might need specify port like this

server httpsserver 10.0.0.80:443 ssl verify none

A simple https server:

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);

POST:

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

HAProxy config:

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

POST against HAProxy

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