【问题标题】:Node http-proxy: forward traffic to external https site - crashes节点 http-proxy:将流量转发到外部 https 站点 - 崩溃
【发布时间】:2017-10-24 20:56:58
【问题描述】:

我想将 REST 请求从我的前端 wepp 应用程序传输到外部 Jira 服务器上的 API。

为此,我使用的是节点 http-proxy,这对于 http 的 Jira 服务器来说是可以的。

但现在我想为 https 创建一个单独的服务器。

所以对this 示例进行一些更改,我现在有了这个:

var path  = require('path'),
    fs    = require('fs'),
    httpProxy = require('http-proxy'),
    certFolder = '/my/cert/folder';

//
// Create the HTTPS proxy server listening on port 8002
//
httpProxy.createServer({

  //(placeholder address)
  target: {
    host: 'https://ext.jiraserver.com',
    port: 443
  },

  // letsencrypt cert
  ssl: {
    key: fs.readFileSync(path.join(certFolder, 'privkey.pem'), 'utf8'),
    cert: fs.readFileSync(path.join(certFolder, 'fullchain.pem'), 'utf8')
  },

  secure: true
}).listen(8002);

console.log('https proxy server started  on port  8002');

但是当我向我的服务器发出请求时,https://my.domain.com:8002 它会使服务器崩溃并显示错误消息:

.../node_modules/http-proxy/lib/http-proxy/index.js:119 抛出错误; ^

错误:getaddrinfo ENOTFOUND https://ext.jiraserver.com https://ext.jiraserver.com:443 在 errnoException (dns.js:28:10) 在 GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

我似乎无法让它工作......服务器在线并且地址正确,所以我不知道出了什么问题。

是我的代码有问题还是我可以做些什么来让它工作?

谢谢!

【问题讨论】:

    标签: javascript node.js reverse-proxy http-proxy


    【解决方案1】:

    不要在 DNS 主机定义中包含 https://

    host: 'ext.jiraserver.com',
    

    错误消息告诉您这是 DNS 解析问题。您正在尝试查找 https://ext.jiraserver.com 的 DNS,包括 https

    【讨论】:

    • 我试过了,我只得到:400 Bad Request - 普通的 HTTP 请求被发送到 HTTPS 端口。感觉就像 httpProxy 启动了一个 http-server,而不是 https?
    • @mottosson 尝试将https: true 添加到target 配置中。
    猜你喜欢
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多