노드 응용 프로그램을 HTTP 및 HTTPS에서 실행하고 싶습니다. 내가 구현 한 StackOverflow에서 몇 가지 코드를 찾았지만 https://
URL을 방문하려고 할 때 시간 초과가 발생합니다. HTTP를 통한 일반적인 방법으로 정상적으로 작동합니다. https://
사이트를 방문 할 때 서버 콘솔에 오류가 표시되지 않습니다. 방문을 시도 할 때 콘솔에서 아무 것도 보지 못했습니다. https://
NodeJS https 시간 초과
서버가 Amazon 플랫폼에서 실행 중입니다.
편집 : 나는 '생산'
sudo NODE_ENV=production forever start app.js
아무도 볼 수에 NODE_ENV
variabele를 설정 서버를 시작할 때 내가 잘못 여기서 뭐 해요?
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);
}
방화벽 문제가 아니라고 주장 했습니까? 포트 443으로 들어오는 연결이 허용됩니까? – robertklep
그게 해결책 이었어! 이것을 답으로 사용할 수 있습니까? – NVO