설치&설정 관련
crt, key 인증서 파일 pem으로 변환
lahuman
2019. 5. 26. 15:08
728x90
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