Sto provando ad avviare un server https node.js.node.js https server che non sta rispondendo
ho iniziato con la creazione di un certificato e una chiave seguendo questa guida:
http://gaboesquivel.com/blog/2014/nodejs-https-and-ssl-certificate-for-development/
e li ho messo nella mia directory /app_name/security/keys
.
per iniziare il mio server HTTPS, ho il seguente:
const https = require('https'),
fs = require('fs');
if(app.get('env') === 'development') {
console.log('dev env!!'); //prints correctly
console.log('port: ' + port); //prints correctly
const options = {
key: fs.readFileSync('./security/keys/key.pem'),
cert: fs.readFileSync('./security/keys/cert.pem')
};
https.createServer(options, (req, res) => {
console.log('https good to go'); //this does not print out anything
}).listen(port);
}
Quando vado al https://localhost:3000
, la pagina genera un errore
This site can’t be reached
localhost unexpectedly closed the connection.
ERR_CONNECTION_CLOSED
Ma non c'è nessun errore sulla console lato server. Inoltre, se vado al normale localhost:3000
, ottengo:
The localhost page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
Qualcuno può aiutarmi?
Grazie in anticipo!
---- ---- UPDATE
Io corro sulla porta 443 ora. Inizialmente ho ottenuto un errore:
Error: listen EACCES 0.0.0.0:443
così mi sono imbattuto:
sudo NODE_ENV=development nodemon app
Che non gettare eventuali errori. Tuttavia, quando sono andato a https://localhost:443
, ottengo:
This site can’t be reached
localhost unexpectedly closed the connection.
credo che potrebbe essere correlato con il porto, https funziona abitualmente su 443 porte. Puoi provare. –
se non viene fornita alcuna porta, funziona su 443. È stata definita una costante di porta. – tanaydin
Gotcha - Ho provato a funzionare su 443 ma sto ancora ottenendo "questo sito non può essere raggiunto". Ho aggiornato la mia domanda con altri dettagli sull'errore. –