我为localhost CN创建了一个自签名SSL证书.Firefox正如预期的那样在最初抱怨之后接受此证书.然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储区之后也是如此.即使我在Chrome的HTTPS弹出窗口中单击"查看证书信息"时列出的证书已正确安装,但仍然坚持认证证书不可信.
我该怎么办才能让Chrome接受证书并停止抱怨?
cd ~/
mkdir .localhost-ssl
sudo openssl genrsa -out ~/.localhost-ssl/localhost.key 2048
sudo openssl req -new -x509 -key ~/.localhost-ssl/localhost.key -out ~/.localhost-ssl/localhost.crt -days 3650 -subj /CN=localhost
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/.localhost-ssl/localhost.crt
npm install -g http-server
echo "
function https-server() {
http-server --ssl --cert ~/.localhost-ssl/localhost.crt --key ~/.localhost-ssl/localhost.key
}
" >> ~/.bash_profile
source ~/.bash_profile
echo "You're ready to use https on localhost "
echo "Navigate to a project directory and run:"
echo ""
echo "https-server"
Run Code Online (Sandbox Code Playgroud)
它不起作用...这段代码有什么问题吗?
代码来源:https://gist.github.com/jonsamp/587b78b7698be7c7fd570164a586e6b7