# 1. SSL ์ธ์ฆ์„œ, Letsencrypt

SSL ์ธ์ฆ์„œ๋Š” ๋ณดํ†ต ์œ ๋ฃŒ๋กœ ๊ตฌ๋งค๋ฅผ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋ฌด๋ฃŒ ์ธ์ฆ์„œ๋ฅผ ์ฃผ๋Š” ๊ณณ์ด ๋ช‡๋ช‡ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. Let's Encrypt (opens new window) : ์œ ๋ฃŒ๊ธฐ๊ฐ„์ด 90์ผ.
  2. Comodo Free SSL (opens new window) : ์ฝ”๋ชจ๋„์—์„œ ์ถœ์‹œํ•œ ๋ฌด๋ฃŒ ์ธ์ฆ์„œ.
  3. CloudFlare One-Click SSL (opens new window) : CloudFlare CDN๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•จ.
  4. 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:

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

๋งŒ์ผ 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