在 Google Chrome 的控制台日志中,我收到以下错误:
GET https://192.168.1.7:8081/sockjs-node/info?t=1579798623564 net::ERR_SSL_PROTOCOL_ERROR
GET https://192.168.1.7/sockjs-node/info?t=1579798623562 net::ERR_CERT_COMMON_NAME_INVALID
如果在/etc/nginx/conf/default.conf (Ubuntu 18.04.03 服务器版):
server {
listen 443 ssl http2 default_server;
server_name example.com www.example.com
ssl_certificate /etc/ssl/certs/chained.pem;
ssl_certificate_key /etc/ssl/private/domain.key;
ssl_certificate /etc/ssl/certs/chained.pem;
ssl_certificate_key /etc/ssl/private/domain.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security "max-age=31536000";
location / {
proxy_pass http://192.168.1.7:8081;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
add_header Strict-Transport-Security "max-age=31536000";
location / {
proxy_pass http://192.168.1.7:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
我设置 vue.config.js 如下:
module.exports = {
productionSourceMap: false,
pluginOptions: {
i18n: {
enableInSFC: true
}
},
devServer: {
host: '192.168.1.7',
hot: true,
disableHostCheck: true
}
}
并定义 webpack.config.js 如下:
var path = require('path');
var fs = require('fs');
module.exports = {
https: {
key: fs.readFileSync('/etc/ssl/private/domain.key'),
ca: fs.readFileSync('/etc/ssl/certs/chained.pem')
}
};
更新 1)
在/etc/nginx/conf.d/default.conf http -> https 中修改:
location / {
proxy_pass https://192.168.1.7:8081;
导致 502 Bad Gateway :
所以......我现在的问题是:如何使用 TLS 让 nginx 服务器回答?
我做错了什么?如何解决问题?
最佳答案
GET https://192.168.1.7:8081/sockjs-node/info?t=1579798623564 net::ERR_SSL_PROTOCOL_ERROR
...
proxy_pass http://192.168.1.7:8081;
在 nginx 配置中,您访问 192.168.1.7:8081
如http://
.在第一行中,您使用 https://
访问相同的 IP:端口这会导致协议(protocol)错误。虽然对该 IP:port 上的服务器一无所知,但很可能只有 http://
。这将解释协议(protocol)错误:尝试对不使用 TLS 应答的服务器进行 TLS 握手。GET https://192.168.1.7/sockjs-node/info?t=1579798623562 net::ERR_CERT_COMMON_NAME_INVALID
关于 192.168.1.7:443
上的证书一无所知(443 是 https 的默认端口)但很可能此证书不包含 192.168.1.7
作为有效的 IP SAN。但这是使用 URL https://192.168.1.7/
时证书验证的预期值。 .
关于vue.js - 获取 : ERR_SSL_PROTOCOL_ERROR nginx + vue. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59883945/