NodeJS https超时

我想在HTTP和HTTPS上运行我的节点应用程序。 我在StackOverflow上find了一些我实现的代码,但是当我想要访问https:// URL的时候,我得到了一个超时。 通过HTTP正常的方式工作正常。 而当我想访问https://网站时,在服务器控制台上看不到任何错误。 当我尝试通过https://访问时,我没有看到控制台上的任何内容

服务器在Amazon平台上运行。

编辑:当我启动服务器时,我设置NODE_ENV变种'生产'

 sudo NODE_ENV=production forever start app.js 

任何人都可以看到我在这里做错了吗?

 var env = process.env.NODE_ENV || 'development'; require('./config/config').set(env);//set configuration console.log(env); var config = require('./config/config').config; var express = require('express'); var debug = require('debug')('juweliergids:server'); var http = require('http'); require('./config/mongoose'); /** * Get port from environment and store in Express. */ var port = normalizePort(config.port); var app = express(); var compact = require('./config/compact')(app, config); require('./config/express')(app, config, compact); require('./config/routes')(app, config, compact); app.set('port', config.port); /** * Create HTTP and HTTPS server. */ var httpServer = http.createServer(app); httpServer.listen(port); httpServer.on('error', onError); httpServer.on('listening', onHttpListening); if(env === 'production'){ var https = require('https'); var fs = require('fs'); var privateKey = fs.readFileSync('/etc/letsencrypt/live/domain.com/privkey.pem'); var certifcate = fs.readFileSync('/etc/letsencrypt/live/domain.com/fullchain.pem'); var credentials = { key: privateKey, cert: certifcate, rejectUnauthorized:false } var httpsServer = https.createServer(credentials, app); httpsServer.listen(443); httpsServer.on('error', onError); httpsServer.on('listening', onHttpsListening); } /** * Normalize a port into a number, string, or false. */ function normalizePort(val) { var port = parseInt(val, 10); if (isNaN(port)) { // named pipe return val; } if (port >= 0) { // port number return port; } return false; } /** * Event listener for HTTP server "error" event. */ function onError(error) { if (error.syscall !== 'listen') { throw error; } var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; // handle specific listen errors with friendly messages switch (error.code) { case 'EACCES': console.error(bind + ' requires elevated privileges'); process.exit(1); break; case 'EADDRINUSE': console.error(bind + ' is already in use'); process.exit(1); break; default: throw error; } } /** * Event listener for HTTP server "listening" event. */ function onHttpListening() { var addr = httpServer.address(); var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; console.log('HTTP server is listening on ' + bind); debug('HTTP server is listening on ' + bind); } function onHttpsListening() { var addr = httpsServer.address(); var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; console.log('HTTPS server is listening on ' + bind); debug('HTTPS server is listening on ' + bind); } 

超时往往表明防火墙问题,特别是当你没有看到任何显示在你的日志文件中,表明连接正在build立。

所以检查你的防火墙,如果它允许传入连接到端口443。