NodeJS Express reverse proxy TLS_CERT_ALTNAME_INVALID error

I have a reverse proxy on my endpoint like this:

var express = require('express');
var app = express();
var httpProxy = require('http-proxy');
var apiProxy = httpProxy.createProxyServer();
var serverOne = '';

app.all('/idena', function (req, res) {
  apiProxy.web(req, res, {target: serverOne});

app.listen(3000, function () {

When a request to /idena is received, the server throws an exception like this:

Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames:, at Object.checkServerIdentity (tls.js:235:17) at TLSSocket.onConnectSecure (_tls_wrap.js:1061:27) at TLSSocket.emit (events.js:189:13) at TLSSocket._finishInit (_tls_wrap.js:633:8)

How can I solve this? Guess is due to https but no idea of how to avoid that, thanks!



Although the error is about mismatching SSL certificate and domain names, in http-proxy module, the error often manifests when your server is HTTP and the Target is HTTPS.

You can avoid this error through the change changeOrigin flag.

const proxy = httpProxy.createProxyServer();

proxy.web(req, res, {
  changeOrigin: true,

In case your server is HTTPS and target one is HTTPS as well, you should include SSL certificate

  ssl: {
    key: fs.readFileSync('valid-ssl-key.pem', 'utf8'),
    cert: fs.readFileSync('valid-ssl-cert.pem', 'utf8')
  target: '',
  secure: true

Please see this question.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.