我正在开发基于 yeoman 的 angular.js 应用程序。
我们已将 gruntfile 设置为通过 https 运行。
它在我同事的机器上运行良好,但在我的机器上运行不佳。
在 Chrome 中我得到:
SSL connection error.
Unable to make a secure connection to the server.
This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
在 Firefox 中我得到:
The connection was interrupted
The connection to localhost:9000 was interrupted while the page was loading.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
我已经仔细检查过我们安装了相同的 npm 模块。
gruntfile 的相关部分是
connect: {
options: {
port: 9000,
hostname: 'localhost',
protocol: 'https',
key: grunt.file.read('server.key').toString(),
cert: grunt.file.read('server.crt').toString(),
ca: grunt.file.read('ca.crt').toString(),
passphrase: 'grunt',
},
livereload: {
options: {
protocol: 'https',
middleware: function (connect) {
return [
modRewrite([
'^/api/(.*) /api/index.php?$1 [L]',
'!\\.html|\\.js|\\.php|\\.css|\\.png$ /index.html [L]'
]),
lrSnippet,
phpGateway('app'),
mountFolder(connect, '.tmp'),
mountFolder(connect, yeomanConfig.app)
];
}
}
},
我的同事生成了证书文件,但这并不重要,因为我有这些文件的精确副本。
最奇怪的部分是,我仍然可以通过 http 运行该网站,而在我同事的机器上,它根本不会通过 http 运行,只能通过 https 运行。
还有其他人能想到的原因吗?
最佳答案
基于错误“这可能是服务器的问题,或者可能需要您没有的客户端身份验证证书”,并且它在您 friend 的计算机上运行而不是您的计算机这一事实使我相信这是您计算机上的 SSL key 和证书的问题。您可以使用此处的教程生成自己的:http://www.akadia.com/services/ssh_test_certificate.html
key: grunt.file.read('server.key').toString(),
cert: grunt.file.read('server.crt').toString(),
ca: grunt.file.read('ca.crt').toString()
确保上述文件位于运行 grunt 的基本文件夹中。 ca.crt 文件对于使用您通过上述教程创建的证书颁发机构对自己的证书进行自签名也是必需的。希望这有帮助!
关于ssl - 使用 grunt 服务器运行 SSL 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18821087/