我在 Mac OS X 上运行节点 v4.1.1 和 npm 2.14.4。对于同一个快速应用程序,我想启动一个 http 和 https 服务器。http 一个运行得非常完美,但另一个崩溃并导致错误:
if (process.features.tls_npn && !opts.NPNProtocols) {
^
TypeError: Cannot read property 'NPNProtocols' of undefined
at new Server (https.js:13:40)
at Object.exports.createServer (https.js:37:10)
以下代码运行整个 express 应用程序并调用 http 方法:
#!/usr/bin/env node
var app = require('./src')
, config = require('./config')
, cmd = require('commander')
, http = require('http')
, https = require('https')
, path = require('path')
cmd
.version('0.1.42')
.option('-p, --port <n>', 'Port to start the HTTP server', parseInt)
.parse(process.argv)
// Launch server with web sockets
var server = http.createServer(app)
var sslServer = https.createServer({
key: fs.readFileSync('ryans-ley.pem'),
cert: fs.readFileSync('ryans-cert.pem')
}, app)
// Listen on provided port, on all network interfaces.
server.listen(config.port || cmd.port, function () {
console.log('http marketplace started on %s:%s',
server.address().address,
server.address().port)
})
sslServer.listen(443, function () {
console.log('https marketplace started on %s:%s',
sslServer.address().address,
sslServer.address().port)
})
这些证书是使用本指南生成的:https ://nodejs.org/api/tls.html#tls_tls_ssl 。
如果我运行相同的代码,而不提供选项,https.createServer
它不会崩溃。但是,当尝试访问https://localhost时,浏览器会回答ERR_SSL_VERSION_OR_CIPHER_MISMATCH
(chrome browser)
卷曲
curl https://localhost
curl: (35) Unknown SSL protocol error in connection to localhost:-9824