gpt4 book ai didi

node.js - NodeJS http-代理 : DEPTH_ZERO_SELF_SIGNED_CERT error when proxying https

转载 作者:搜寻专家 更新时间:2023-10-31 22:25:59 27 4
gpt4 key购买 nike

我正在使用最新版本的 nodejs 和 http-proxy 关注在线示例,但是当我的请求发送到端点 https 服务器时出现以下错误:

C:\Users\Me\node_modules\http-proxy\lib\http-proxy\index.js:114
throw err;
Error: DEPTH_ZERO_SELF_SIGNED_CERT
at SecurePair.<anonymous> (tls.js:1370:32)
at SecurePair.EventEmitter.emit (events.js:92:17)
at SecurePair.maybeInitFinished (tls.js:982:10)
at CleartextStream.read [as _read] (tls.js:469:13)
at CleartextStream.Readable.read (_stream_readable.js:320:10)
at EncryptedStream.write [as _write] (tls.js:366:25)
at doWrite (_stream_writable.js:226:10)
at writeOrBuffer (_stream_writable.js:216:5)
at EncryptedStream.Writable.write (_stream_writable.js:183:11)
at write (_stream_readable.js:582:24)

我的代码很简单:

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

var apimcert = fs.readFileSync('./mycert.pfx');
var proxy = httpProxy.createProxyServer({});

var options = {
pfx: apimcert,
passphrase : 'pAssw0rd',
rejectUnauthorized : 'false',
agent: false
};

var server = require('https').createServer(options, function(req, res) {
console.log("Got a request " + req);
proxy.web(req, res, {
ssl: {
pfx : apimcert,
passphrase : 'pAssw0rd',
rejectUnauthorized : 'false'

//strictSSL: false
},
target: 'https://endpointhost:9443/postev',
secure: true
}

);
});

console.log("listening on port 9442")
server.listen(9442);

如果我设置 secure : false 那么请求会被转发到端点,但显然会返回一个 403 forbidden 响应。我使用的证书和密码来 self 的端点服务器,我已经测试过它们在直接发送请求时确实有效。我想让我的代理做的就是检查请求的内容,为每个请求记录一条消息,然后转发到端点服务器。

我用谷歌搜索了这个问题并尝试摆弄代理和 strictSSL,但无济于事。

最佳答案

我正在使用 Ant design proumi。只需将此 secure: false, 添加到 proxy.ts

proxy: {
'/myapi': {
target: 'https://localhost:8443',
changeOrigin: true,
secure: false, // 不进行证书验证
},

umi 会自动刷新配置,刷新浏览器即可。

关于node.js - NodeJS http-代理 : DEPTH_ZERO_SELF_SIGNED_CERT error when proxying https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24887787/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com