-
crt, key 인증서 파일 pem으로 변환설치&설정 관련 2019. 5. 26. 15:08728x90
cert, key 파일을 pem 파일로 변환 하기
nginx에서 사용하던 인증서를 nodejs에서 바로 사용을 하기 위해 pem 파일 형식으로 변경 해야하는 일이 생겨서 검색을 해보았다.
파일 형석의 변환은 다음과 같이 쉽게 할 수 있다.# key 변경 openssl rsa -in server.key -text > private.pem # crt 변경 openssl x509 -inform PEM -in server.crt > public.pem
추가 팁] nodejs 에서 https 설정
nodejs에서 https 사용을 위해서는 https 모듈을 추가로 설치 해야 한다.
이후 소스내에 다음과 같이 인증서를 options을 추가 하면 된다.
const https = require('https'); const fs = require('fs'); const options = { ca: fs.readFileSync('인증서경로/ca-bundle.pem') key: fs.readFileSync('인증서경로/domain_xxxxx.key.pem') cert: fs.readFileSync('인증서경로/domain_xxxxx.crt.pem') }; https.createServer(options, (req, res) => { res.writeHead(200); res.end('hello world\n'); }).listen(443);
참 쉽죠?
참고 주소
728x90'설치&설정 관련' 카테고리의 다른 글
MongoDB aggregate 사용해보기 (0) 2019.05.26 puppeteer를 Ubuntu에 설치하고 기동하기 (0) 2019.05.26 AWS LAMBDA를 이용해서 개발하다 (0) 2019.05.26 80 port에 대하여 Root가 아닌 다른 계정으로 서비스 하기 (0) 2019.02.06 Nginx private 인증서 적용하기 (0) 2019.02.06