# 1. SSL ์ธ์ฆ์, Letsencrypt
SSL ์ธ์ฆ์๋ ๋ณดํต ์ ๋ฃ๋ก ๊ตฌ๋งค๋ฅผ ํด์ผํฉ๋๋ค. ๊ทธ๋ฌ๋ ๋ฌด๋ฃ ์ธ์ฆ์๋ฅผ ์ฃผ๋ ๊ณณ์ด ๋ช๋ช ์์ต๋๋ค.
- Let's Encrypt (opens new window) : ์ ๋ฃ๊ธฐ๊ฐ์ด 90์ผ.
- Comodo Free SSL (opens new window) : ์ฝ๋ชจ๋์์ ์ถ์ํ ๋ฌด๋ฃ ์ธ์ฆ์.
- CloudFlare One-Click SSL (opens new window) : CloudFlare CDN๊ณผ ํจ๊ป ์ฌ์ฉ ๊ฐ๋ฅํจ.
- AWS Certificate Manager (opens new window) ์ ํจ๊ธฐ๊ฐ ์๋ ๊ฐฑ์ .
๊ทธ์ธ ๋ ์์ง๋ง ์ฌ๊ธฐ์๋ Let's Encrypt๋ฅผ ์ด์ฉํด์ ์ธ์ฆ์๋ฅผ ๋ฐ์์ต๋๋ค.
์๋์ฐ ์๋ฒ์์ ํ ์คํธ๋ฅผ ํ ์์ ์ด๋ผ letsencrypt-win-simple (opens new window) ์ด์ฉํ์ฌ ์ธ์ฆ์๋ฅผ ๋ฐ์์ต๋๋ค. letsencrypt-win-simple (opens new window) ์ ์์ธํ ๋ด์ฉ์ wiki (opens new window) ๋ฅผ ์ฐธ๊ณ ํ์ธ์.
# 2. HTTPS ์๋ฒ ๊ตฌํ
Node.js HTTPS Documentation (opens new window)๋ฅผ ์ฐธ๊ณ ํ์ธ์.
์์ ๋ ์๋์ ๊ฐ์ต๋๋ค.
๋ฐฉ๋ฒ 1:
// curl -k https://localhost:8000/
const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};
https.createServer(options, (req, res) => {
res.writeHead(200);
res.end('hello world\n');
}).listen(8000);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
๋ฐฉ๋ฒ 2:
const https = require('https');
const fs = require('fs');
const options = {
pfx: fs.readFileSync('test/fixtures/test_cert.pfx'),
passphrase: 'sample'
};
https.createServer(options, (req, res) => {
res.writeHead(200);
res.end('hello world\n');
}).listen(8000);
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
๋ง์ผ Express (opens new window)๋ฅผ ์ด์ฉํ์ฌ ๊ตฌํํ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ๊ตฌํํ๋ฉด ๋ฉ๋๋ค.
with Express:
const express = require('express');
const https = require('https');
const http = require('http');
const fs = require('fs');
const options = {
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.cert')
};
// Create a service (the app object is just a callback).
const app = express();
// Create an HTTP service.
http.createServer(app).listen(80);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(443);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17