有没有办法在 Express 上为 SSL 设置自定义端口?这仅用于开发目的。我在 80/443 上有一个 Apache/PHP 项目。
我试过按照本教程 http://www.hacksparrow.com/express-js-https.html
但老实说,我无法让它发挥作用。如果有人可以发布正确的方式来配置 Express 来做到这一点,那将是非常棒的。这是我的服务器配置:
var hskey = fs.readFileSync('mywebsite-key.pem');
var hscert = fs.readFileSync('mywebsite-cert.pem')
var options = {
key: hskey,
cert: hscert
};
//Create server
var app = express(options);
// Configure server
app.configure(function () {
//parses request body and populates request.body
app.use(express.bodyParser());
//checks request.body for HTTP method overrides
app.use(express.methodOverride());
//perform route lookup based on url and HTTP method
app.use(app.router);
//Where to serve static content
app.use(express.static(path.join(application_root, 'public')));
//Show all errors in development
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
//Start server
var port = nconf.get('port');;
var server = require('http').createServer(app),
io = require('socket.io').listen(server);
server.listen(port, function () {
console.log('Express server listening on port %d in %s mode', port, app.settings.env);
});