Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- ES6
- 운영체제
- 노드
- 백준
- 컴퓨터 보안
- 컴퓨터보안
- API문서
- 자바스크립트
- 디비
- 컴퓨터
- AWS
- 탐욕기법
- node
- 데이터베이스
- 백트래킹
- OS
- 인터럽트
- 되추적
- 알고리즘
- IT
- DB
- NEST
- 병행제어
- access control
- 보안
- node.js
- rest docs
- DATABASE
- S3
- 스프링부트
Archives
- Today
- Total
개발스토리
https와 http2 본문
https 모듈은 웹 서버에 SSL 암호화를 추가한다. GET이나 POST 요청을 할 때 오가는 데이터를 암호화해서 중간에 다른 사람이 요청을 가로채더라도 내용을 확인할 수 없게 한다.
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</h1>');
res.end('<p>hi</P>');
}).listen(443,()=>{
console.log('server start');
});
- createServer 메서드가 인수를 두 개 받는다. 인증서를 구입하면 pem이나 crt, key 확장자를 가진 파일들을 제공한다.
노드의 http2 모듈은 SSL 암호화와 더불어 최신 HTTP 프로토콜인 http/2를 사용할 수 있게 한다.
const http2 = require('http2');
const fs = require('fs');
https.createSecureServer({
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</h1>');
res.end('<p>hi</P>');
}).listen(443,()=>{
console.log('server start');
});
Comments