问题描述
我在macOS Sierra 10.12.3中使用Chrome.我想我很早以前已经为localhost
设置了ssl
.现在,Chrome中的http://localhost/
和https://localhost/
都将返回localhost
下的文件夹列表.我已经创建了一个nodejs应用程序.因此,在命令行中输入npm start
来运行服务器后,我们可以在Chrome中以的形式打开http://localhost:3000/#/home
.
I use Chrome in macOS Sierra 10.12.3. I guess I have already set up ssl
for localhost
long time ago. Now, both http://localhost/
and https://localhost/
in Chrome return the list of folders under localhost
. I have created a nodejs app. So after typing npm start
in a command line to run the server, we could open http://localhost:3000/#/home
as frond-end in Chrome.
现在,由于某些原因,我需要使https://localhost:3000/#/home
在Chrome中运行.目前,它会显示This site can't be reached; localhost unexpectedly closed the connection
错误.
Now, for some reason, I need to make https://localhost:3000/#/home
work in Chrome. At the moment, it gives This site can't be reached; localhost unexpectedly closed the connection
error.
有人知道如何修改吗?我应该在Mac中还是在我的应用程序代码中设置某些内容?
Does anyone know how to amend this? Should I set up something in mac or in the code of my app?
我已经找到此页面:具有Node.js和Express.js的SSL/HTTPS服务器.因此,我生成了文件并修改了节点代码.现在,加载https://localhost:3000/#/posts/editor/
将显示该页面,但我想删除烦人的Not Secure
警告.
Edit 1: I have found this page: SSL/HTTPS server with Node.js and Express.js. So I generated the files and modified the node code. Now loading https://localhost:3000/#/posts/editor/
displays the page, but I want to remove the annoying Not Secure
warning.
如上面的屏幕快照所示,我能够查看其证书(尽管出现错误ERR_CERT_COMMON_NAME_INVALID
).我将证书复制到桌面,并将其拖到Keychain Access
工具的login
上,并将其设置修改为Always Trust
.我重新启动了Chrome,重新加载了页面,但Not Secure
警告仍然存在.
As the above screenshot shows, I was able to view its certificate (though there is an error ERR_CERT_COMMON_NAME_INVALID
). I copied the certificate to the desktop and dragged it to login
of the Keychain Access
tool and modified its setting to Always Trust
. I restarted Chrome, reloaded the page, but the Not Secure
warning is still there.
有人可以帮忙吗?
推荐答案
关于此问题,实际上有很多线程,这很令人困惑.我写出对我有用的方式.
There are actually lots of threads about this issue, which are quite confusing. I write the way that works for me.
-
我终于按照此页面生成了文件"> http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/.请注意,我将
localhost
设置为Common Name
(不确定是否确实是强制性的).
I have finally followed this page to generate the files http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/. Note that I set
localhost
asCommon Name
(not sure if it's really mandatory).
在我的MEAN项目的www
中
In www
of my MEAN project
var fs = require("fs");
var config = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
var server = https.createServer(config, app).listen(3000);
在Chrome中,打开https://localhost:3000/#/new
,然后转到Dev Tools
的Security
选项卡以查看其证书.然后将证书拖到桌面上.
In Chrome, I open https://localhost:3000/#/new
, then I go to the Security
tab of Dev Tools
to view its certificate. Then drag the certificate to the desktop.
双击桌面上的证书,这将打开Keychain Access
.确保证书在login
中(不一定是system
).如果不是,则将证书拖到login
.
Double-click the certificate on the desktop, which opens Keychain Access
. Make sure the certificate is in login
(not necessarily system
). If it's not, then drag the certificate in login
.
将所有内容更改为Always Trust
(可能重新启动Chrome
),在npm start
应用程序之后,可以使用Green Secure Light浏览https://localhost/#/new
.
(maybe restart Chrome
), after npm start
the application, enjoy surfing https://localhost/#/new
with Green Secure Light.
这篇关于在Chrome&中信任MEAN堆栈的https://localhost:3000/苹果电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!