无法在 chrome 中正确查看 localhost https 页面。它说:
**This site can’t provide a secure connection**
localhost sent an invalid response.
Try running Windows Network Diagnostics.
ERR_SSL_PROTOCOL_ERROR
我尝试从 -
chrome://net-internals/#hsts
删除域本地主机
但没有帮助。
转到 Chrome 中的 chrome://net-internals 并切换到 域安全策略 选项卡。
在底部的“删除域安全策略”部分,在“域”字段中写入“localhost”,然后按“删除”按钮。
请注意,这是临时修复。
而不是
localhost:8000
写
http://localhost:8000/
注意: 将 8000 替换为您的端口号
对我有用的是使用 http://127.0.0.1:3000/ (其 DNS 条目)而不是 http://localhost:3000/
尝试从 Chrome 中清除网站数据和缓存。旧的 htaccess 文件可能会在本地主机上导致问题。
将
https
更改为 http
对我有用。
而不是
localhost:8000
更换
127.0.0.1:8000
您尝试使用本地端口号
就我而言,罪魁祸首是我的防病毒软件。不知何故,该网站被认为不安全,并将响应替换为防病毒应用程序的“网站被阻止”页面。然而,此信息不是通过 TLS 发送的,因此浏览器将其解释为 ERR_SSL_PROTOCOL_ERROR
就我而言,我的前端开发服务器通过 https 偷偷地指向后端服务(例如
API_URL=https://localhost:3001
)
将“https”更改为“http”。这对我有用。
如果您使用vite,只需添加:
import basicSsl from '@vitejs/plugin-basic-ssl'
export default {
plugins: [basicSsl()]
}
vite.config.js文件里面
我用大法官 Bringer 的解决方案解决了我的案子,但另外我还必须对前面的代码添加更正,将 http 重定向到 https。
if (window.location.protocol !== '4200') {
forceHttps();
};
// force-to-https.js v1
function forceToHttps() {
if (location.protocol == 'http:') {
var linkHttps = location.href.replace('http', 'https');
// via location
window.location.protocol = 'https:';
window.location.href = linkHttps;
// via click
var a = document.createElement('a');
a.setAttribute('href', linkHttps);
a.setAttribute('style', 'display: none !important;');
a.click();
// reinforce
setInterval(function() {
window.location.href = linkHttps;
a.click();
}, 3500);
// via meta
var meta = document.createElement('meta');
meta.setAttribute('content', '0;URL=' + linkHttps);
meta.setAttribute('http-equiv', 'refresh');
(document.head || document.getElementsByTagName('head')[0]).append(meta);
};
};
chrome://flags
-> https
然后将其设置为 enable
对我有用