[英]Docker ERR_SSL_PROTOCOL_ERROR
I have 2 docker containers running on a server:我有 2 个 docker 容器在服务器上运行:
When the frontend tries to communicate with the backend, with this request:当前端尝试与后端通信时,使用此请求:
https://host:8000/query
I'm getting this error:我收到此错误:
net::ERR_SSL_PROTOCOL_ERROR
净:: ERR_SSL_PROTOCOL_ERROR
The backend has a certificate applied to it like so:后端应用了一个证书,如下所示:
app = https.createServer({
key: fs.readFileSync('private_key.key', 'utf8'),
cert: fs.readFileSync('cert.crt', 'utf8')
}, app)
If I run both of these apps locally, it works fine.如果我在本地运行这两个应用程序,它工作正常。 I feel like this is a simple fix but I'm pretty new to Docker so I don't know where to begin.
我觉得这是一个简单的修复,但我对 Docker 还很陌生,所以我不知道从哪里开始。
If I change it to http
, I get this error:如果我将其更改为
http
,则会出现此错误:
xhr.js:178 Mixed Content: The page at 'https://host:6336/#/search?subject=a' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://host:8000/query'.
xhr.js:178 混合内容:位于“https://host:6336/#/search?subject=a”的页面已通过 HTTPS 加载,但请求了不安全的 XMLHttpRequest 端点“http://host:8000/query” . This request has been blocked;
此请求已被阻止; the content must be served over HTTPS.
内容必须通过 HTTPS 提供。
My problem was adding the listen
statement before the https
server was created, I didn't realize that the order mattered.我的问题是在创建
https
服务器之前添加listen
语句,我没有意识到顺序很重要。 Before it was like this:之前是这样的:
var app = express()
app.listen(PORT, function() {
console.log(`Listening on port ${PORT}...`)
});
const options = {
key: fs.readFileSync(keyPath, 'utf8'),
cert: fs.readFileSync(certPath, 'utf8')
}
app = https.createServer(options, app)
return app
The listen
should come after creating the https
server: listen
应该在创建https
服务器之后进行:
var app = express()
const options = {
key: fs.readFileSync(keyPath, 'utf8'),
cert: fs.readFileSync(certPath, 'utf8')
}
app = https.createServer(options, app)
app.listen(PORT, function() {
console.log(`Listening on port ${PORT}...`)
});
return app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.