맥에서 로컬 개발환경을 https 로 만들기 위해서는 직접 ssl 인증서를 만들고 macOS에 등록하는 과정이 필요하다.
1. ssl 인증서 만들기
- https://letsencrypt.org/docs/certificates-for-localhost/ 참고
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
위 커맨드에서 localhost 대신 /etc/hosts에 등록한 다른 주소를 넣으면 해당 주소에 대한 인증서를 만들 수 있다.
2. macOS 키체인 어플리케이션에 등록
Finder -> 응용 프로그램 -> 유틸리티 -> 키체인 접근 어플리케이션 실행
상단 파일 메뉴 -> 항목 가져오기 -> 생성된 crt 파일 가져오기
키체인 앱 리스트에 추가된 인증서 더블클릭 -> 신뢰 탭 -> 이 인증서 사용시: 항상 신뢰 선택후 닫기
3. 사용하고 있는 웹 서버에(여기서는 nginx) 해당 인증서를 사용하도록 설정 추가
- nginx.conf 파일에 다음을 추가
server {
listen 443;
ssl on;
ssl_certificate /파일위치/localhost.crt;
ssl_certificate_key /파일위치/localhost.key;
server_name localhost;
location / {
proxy_pass http://localhost;
}
}
이 경우는 개발용 서버를 localhost 80포트에 http로 띄운 상태에서 https 통신을 위해 443 포트를 프록시로 연결해준 경우이다. 필요에 따라서 직접 서버를 연결하는 등의 설정.
4. 완료
이제 개발서버를 띄운 후 https://localhost 에 접속해보면 주소창 왼쪽에 정상적으로 인증되었다는 자물쇠 아이콘을 볼 수 있다.
'프로그래밍' 카테고리의 다른 글
레거시 코드에 대해 (3) | 2021.09.09 |
---|