node.js로 https로 웹서버 띄우기 > BlockChain 자료실

본문 바로가기
사이트 내 전체검색

BlockChain 자료실

node.js로 https로 웹서버 띄우기

페이지 정보

profile_image
작성자 조선제일검
댓글 0건 조회 1,741회 작성일 22-07-22 00:26

본문

1. https 및 보안키 모듈 로드
// https 보안적용
var fs = require('fs');
var https = require('https');
// 보안키 파일
var privateKey = fs.readFileSync('cert/server.key''utf8');
var certificate = fs.readFileSync('cert/server.crt''utf8');
var credentials = {key: privateKeycert: certificate};


2. 보안키 생성
 리눅스에서 openssl 설치
ubuntu -> sudo apt-get install openssl


image.png

3. 개인키 발급
openssl genrsa 1024 > key.pem
RSA 알고리즘으로 1024bit의 개인키를 만들겠다.

image (1).png

image (2).png

 

4. 개인키로 디지털 인증서 생성
openssl req -x509 -new -key key.pem > cert.pem
 

image (3).png

 

 

인증서 파일이 만들어졌다. But 공인된 인증서는 아니다.

5. 파일 이동
생성된 두 개의 개인키와 디지털 인증서를 node.js 프로젝트의 cert 디렉토리에 옮겨서
Sync할 수 있도록 한다.
var privateKey = fs.readFileSync('cert/server.key''utf8');
var certificate = fs.readFileSync('cert/server.crt''utf8');
var credentials = {key: privateKeycert: certificate};

6. httpsServer 함수선언
// httpsServer 서버 생성 후 보안키 파일 적용
// credentials : 개인키, 인증서 로드, app : express 객체변수
var httpsServer = https.createServer(credentialsapp);
// var server = httpsServer.listen(port);
var server = httpsServer.listen(portfunction(){

console.log('Express HttpsServer Apply'port);
});
 

 

 

 

 

 

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

회사명 : (주)리눅스데이타시스템 / 대표 : 정정모
서울본사 : 서울특별시 강남구 봉은사로 114길 40 홍선빌딩 2층 / tel : 02-6207-1160
대전지사 : 대전광역시 유성구 노은로174 도원프라자 5층 / tel : 042-331-1161

접속자집계

오늘
854
어제
1,434
최대
3,935
전체
802,003
Copyright © www.linuxdata.org All rights reserved.