domingo, 25 de diciembre de 2016

https web server with ubuntu, letsencript and nodejs

sudo apt-get install letsencrypt
letsencrypt certonly --standalone -d

Note: this will generate the following files in folder /etc/letsencrypt/live/ cert.pem chain.pem fullchain.pem privkey.pem

Now you are ready to implement and execute your nodejs https server. Run the following program and then open and it should be working without any browser warning, ready for production.

const https = require('https');
const fs = require('fs');

// cert.pem  chain.pem  fullchain.pem  privkey.pem

const options = {
  key: fs.readFileSync('/etc/letsencrypt/live/'),
  cert: fs.readFileSync('/etc/letsencrypt/live/')

https.createServer(options, (req, res) => {
  res.end('hello world\n');

Or using http-server command line utility:

http-server . -p 443 --ssl --cert "/etc/letsencrypt/live/" --key "/etc/letsencrypt/live/"

No hay comentarios: