我目前有一个HTTPS Web服务器侦听我的主机上的端口443 .
我的目标是在同一主机上设置另一个HTTPS Web服务器,更改两个Web服务器上的端口,然后使用node-http-proxy侦听端口443来设置代理服务器 . 然后,代理服务器将基于自定义逻辑的请求委托给其他端口上的服务器 .
下面是我在端口80上代理普通HTTP请求时成功使用的代理服务器 . 但是,当我尝试运行此代码时,浏览器会显示消息“安全代理服务器此时无法处理您的请求” . 和控制台日志'[错误:UNABLE_TO_VERIFY_LEAF_SIGNATURE]'它确实使它成功地将请求代理到在不同端口上侦听的服务器 .
var sugar = require('sugar')
var url = require('url')
var https = require('https')
var httpProxy = require('http-proxy')
var fs = require('fs')
//configure proxy
var ssl proxy = httpProxy.createProxyServer({
ssl: {
key: fs.readFileSync('/cert/server.key', 'utf-8'),
cert: fs.readFileSync('/cert/mydomain.crt', 'utf-8')
}
})
sslproxy.on(
'error',
function(err, req, res) {
console.log(err)
res.end('Secure Proxy Server unable to handle your request at this time.')
}
)
//configure and start server that uses proxy
var credentials = {
key: fs.readFileSync('/cert/server.key','utf-8'),
cert: fs.readFileSync('/cert/mydomain.crt', 'utf-8')
}
var sslserver = https.createServer(
credentials,
function(req, res) {
console.log("Received request on secure proxy server")
var target = url.parse(req.url)
if(target.pathname.startsWith('/version1')) {
console.log("Forwarding request to port 444")
sslproxy.web(req, res, {target: 'https://localhost:444'})
} else {
console.log("Forwarding request to 445")
sslproxy.web(req, res, {target: 'https://localhost:445'})
}
}
)
sslserver.listen(443)
几个想法:
-
我尝试使用node-ssl-root-cas,如另一个question的答案所示,但似乎没有任何改变 . 我的SSL证书来自Network Solutions .
-
我的代理的目标是localhost:444和localhost:445,因为这些端口不是外部打开而不是 . 不确定主机名中的localhost是否影响https代理 .
1 回答
试试这个:process.env ['NODE_TLS_REJECT_UNAUTHORIZED'] ='0';
看看这个:
解决方案和其他信息都来自这里:Node.js HTTPS 400 Error - 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'