Http-proxy-middleware: ERR_TLS_CERT_ALTNAME_INVALID

Created on 3 Feb 2018  路  8Comments  路  Source: chimurai/http-proxy-middleware

Expected behavior

I'm supposed to get the request via proxy

Actual behavior

I'm getting ALTNAME error

Setup

  • http-proxy-middleware: 0.17.4
  • server: express + 4.15.2
  • other relevant modules

proxy middleware configuration

function relayRequestHeaders(proxyReq, req) {
    Object.keys(req.headers).forEach(function (key) {
        proxyReq.setHeader(key, req.headers[key]);
    });
};

function relayResponseHeaders(proxyRes, req, res) {
    Object.keys(proxyRes.headers).forEach(function (key) {
        res.append(key, proxyRes.headers[key]);
    });
};

const options = {
    target: 'example.com',
    logLevel: 'debug',
    onProxyReq: relayRequestHeaders,
    onProxyRes: relayResponseHeaders
}

server mounting

var app = express();

app.use('/apps', proxy(options));
app.listen(3000);

Most helpful comment

Had same issue.
Added changeOrigin to fix this and pathRewrite to fix 404

  const apiProxy = proxy('/api', {
    target: API_ENDPOINT,
    changeOrigin: true,
    pathRewrite: { '^/api': '' }, // remove leading /api to match real API urls
  })

All 8 comments

When ever I add changeOrigin: true I get 404 errors. Any help?

@coderpradp Did you ever figure this out?

Getting same error when proxying request to a ssl based server

Had same issue.
Added changeOrigin to fix this and pathRewrite to fix 404

  const apiProxy = proxy('/api', {
    target: API_ENDPOINT,
    changeOrigin: true,
    pathRewrite: { '^/api': '' }, // remove leading /api to match real API urls
  })

What location is this file found at?

I have already set changeOrigin to true.
I think that the error came from a self signed certificate.
then:
how to accept SELF SIGNED certificate in dev environment?

I have already set changeOrigin to true.
I think that the error came from a _self signed_ certificate.
then:
how to accept SELF SIGNED certificate in dev environment?

it seems to be enough to set secure: false

A test https server I was trying to proxy to was using a self signed certificate, I found that by striping all the request headers seemed to allow it to successfully connect and return a response.

I changed the relayRequestHeaders function to this;

function relayRequestHeaders(proxyReq, req) {
  Object.keys(req.headers).forEach(function (key) {
    // strip all the request headers, as the receiving server is freaking out on one of them
    proxyReq.setHeader(key, '');
  });
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghostd picture ghostd  路  7Comments

kimmobrunfeldt picture kimmobrunfeldt  路  5Comments

ubreddy picture ubreddy  路  5Comments

udayms picture udayms  路  8Comments

noahgrant picture noahgrant  路  4Comments