3

私はほとんどこのチュートリアルに従っています(私が見つけた他のすべてのチュートリアルは同じように見えます)

http://www.hacksparrow.com/express-js-https.html

私のコードは次のとおりです。

// dependencies
var express = require('express')
  , https = require('https')
  , fs = require('fs');

var privateKey = fs.readFileSync('./ssl/rp-key.pem').toString();
var certificate = fs.readFileSync('./ssl/rp-cert.pem').toString();

var app = express.createServer({
  key : privateKey
, cert : certificate
});

...

// start server
https.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

sudo node app の後、アプリは正常に起動します

Express server listening on port 443

今私がカールするとき

curl https://localhost/

私は得る

curl: (35) Unknown SSL protocol error in connection to localhost:443

何か案は?

4

1 に答える 1

3

現在npmを介して公開されているExpress3.x以降、「app()」-アプリケーション関数が変更されました。https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.xに移行情報があります。Express2.xSSLチュートリアルはいずれも機能しなくなります。express3.xの正しいコードは次のとおりです。

// dependencies
var express = require('express')
  , https = require('https')
  , fs = require('fs');

var privateKey = fs.readFileSync('./ssl/rp-key.pem').toString();
var certificate = fs.readFileSync('./ssl/rp-cert.pem').toString();

var options = {
  key : privateKey
, cert : certificate
}
var app = express();

...

// start server
https.createServer(options,app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});
于 2012-07-19T19:17:55.613 に答える