https
- 웹 서버에 SSL 암호화를 추가하는 모듈
- 오고 가는 데이터를 암호화해서 중간에 다른 사람이 요청을 가로채더라도 내용을 확인할 수 없음
- HTTPS 적용이 필수(개인 정보가 있는 곳은 특히)
const https = require('https');
const fs = require('fs');
https
.createServer(
{
cert: fs.readFileSync('도메인 인증서 경로'),
key: fs.readFileSync('도메인 비밀키 경로'),
ca: [fs.readFileSync('상위 인증서 경로'), fs.readFileSync('상위 인증서 경로')],
},
(req, res) => {
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
res.write('<h1>hello node!</h1>');
res.end('<p>hello server!</p>');
}
)
.listen(443, () => {
console.log('443서버에서 대기중');
});
http2
- SSL 암호화와 더불어 최신 HTTP 프로토콜인 http/2를 사용하는 모듈
- 요청 및 응답 방식이 기존 http/1.1보다 개선됨
- 웹의 속도도 개선됨
const http2 = require('http2');
const fs = require('fs');
http2
.createServer(
{
cert: fs.readFileSync('도메인 인증서 경로'),
key: fs.readFileSync('도메인 비밀키 경로'),
ca: [fs.readFileSync('상위 인증서 경로'), fs.readFileSync('상위 인증서 경로')],
},
(req, res) => {
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
res.write('<h1>hello node!</h1>');
res.end('<p>hello server!</p>');
}
)
.listen(443, () => {
console.log('443서버에서 대기중');
});