YIk Teng Hie 5 years ago
parent 4ee290c123
commit c82470971b

@ -0,0 +1,42 @@
# Quick Guide of SSL
* Prerequisites
* [OpenSSL](https://www.openssl.org/) tool
* Openssl is preinstall on Linux / MacOS / Git Bash
* For windows, need to build the binary. Alternatively, use Git Bash (Install Git)
* Generate SSL key And cert
```sh
$ openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
// more sample
$ openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
```
## Node JS implementation
* Reference Code for secure server
* Place key and cert file in the `cert` folder of the nodejs project
```js
const express = require('express');
const https = require('https');
const path = require('path');
const fs = require('fs');
const app = express();
app.use('/', (req, res, next) => {
res.send('Hello from SSL Server');
});
const sslServer = https.createServer({
key: fs.readFileSync(path.join(__dirname, 'cert', 'server.key')),
cert: fs.readFileSync(path.join(__dirname, 'cert', 'server.csr))
}, app);
sslServer.listen(3443, () => console.log('Secure Server on port 3443'));
```
Loading…
Cancel
Save