Skip to content

Proxying https gives 400 bad request/502 bad gateway #366

Closed
phun-ky opened this Issue Jan 16, 2013 · 1 comment

2 participants

@phun-ky
phun-ky commented Jan 16, 2013

I've got this code for proxy requests:

var http = require('http'),
    httpProxy = require('http-proxy');


//
// Create a proxy server with custom application logic
//
httpProxy.createServer(function (req, res, proxy) {
  //
  // Put your custom server logic here
  //
  var proxyOpts = {};

  if (req.url.match('/api/customer')) {
    req.url = req.url.replace('/api/customer', '/customer-rest-api/customer');
    proxyOpts = {
      host: 'working.domain',
      port: 12010
    };

  } else if ( req.url.match('/bootstrap')){

    proxyOpts = {
      host: 'www2.domainonhttps.com',
        port: 443,
        target : {
          https: true
        }

    };
  } else {
    proxyOpts = {
      host: 'localhost',
      port: 8094
    };
  }



  proxy.proxyRequest(req, res, proxyOpts);


}).listen(8000);

Every route except for the www2.domainonhttps.com route is working. When I set target, I get a 400 bad request error. If I don't set target, I get a "502 bad gateway error". The destination domain + path is working fine through a browser.

What could be the issue here? Is there some options I've neglected to add? I was trying to find a working http-> https example for this application, but it's nowhere to be found.

@indexzero
nodejitsu member

Yes, should be:

proxyOpts = {
  host: 'www2.domainonhttps.com',
  port: 443,
  https: true
};
@indexzero indexzero closed this Mar 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.