0

I am having issues getting https working with node http-proxy.

I've created a server using node http-server

forever /usr/local/lib/node_modules/http-server/bin/http-server /home/blah/public_html/ -p 5000 -S -C /myencrypt/blah.com/cert.pem -K /myencrypt/blah.com/privkey.pem

If I go to https://blah.com:5000 the Certs are working correctly.

If I go to blah.com I get the following error

Error: unable to verify the first certificate
    at TLSSocket.<anonymous> (_tls_wrap.js:1088:38)
    at emitNone (events.js:86:13)
    at TLSSocket.emit (events.js:188:7)
    at TLSSocket._finishInit (_tls_wrap.js:610:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:440:38)

What am I missing here?

var fs = require('fs');
var http = require('http');
var https = require('https');
var httpProxy = require('http-proxy');

var proxy = httpProxy.createProxy();
var options = {  
  'blah.com':{
    target:'https://blah.com:5000',
    ssl:{
      key:fs.readFileSync('/myencrypt/blah.com/privkey.pem', 'utf8'),
      cert:fs.readFileSync('/myencrypt/blah.com/cert.pem', 'utf8')
    }
  }
}

http.createServer(function(req, res) {
  proxy.web(req, res, {
    target: options[req.headers.host].target,
    ssl : options[req.headers.host].ssl
  });
}).listen(80);
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
K3NN3TH
  • 1,458
  • 2
  • 19
  • 31

1 Answers1

0

I decided to solve my problem using redbird

var redbird = require('redbird')({
    port: 80,
    secure:false,
    ssl: {
        port:443,
        key: "/myencrypt/blah.com/privkey.pem",
        cert: "/myencrypt/blah.com/cert.pem",
    }
});

redbird.register('blah.com', 'https://blah.com:5000', {
    ssl: {
        key: "/myencrypt/blah.com/privkey.pem",
        cert: "/myencrypt/blah.com/cert.pem",
    }
});
K3NN3TH
  • 1,458
  • 2
  • 19
  • 31