Nginx 에 자체 서명 인증서 붙여 HTTPS 시험
openssl 로 자체 서명 인증서를 만들어 Nginx 에 붙이고, curl 이 내는 self-signed certificate 오류와 -k·--cacert 의 차이를 시험합니다.
공개 도메인이 없어도 Nginx 의 ssl 설정이 맞는지는 자체 서명 인증서로 확인할 수 있습니다. 아래는 포트 18843 에서 시험한 결과이고, 실제 서비스 인증서를 대신하는 방법은 아닙니다. Nginx 설치는 이 글에 있습니다.
[1] 인증서와 키를 만듭니다. -nodes 는 키에 암호를 걸지 않는다는 뜻이고(Nginx 가 시작할 때 암호를 물을 수 없습니다), -addext 로 subjectAltName 을 넣습니다. 요즘 클라이언트는 주체 이름을 이 항목에서 찾습니다.
$ mkdir -p /srv/tls-test/certs && cd /srv/tls-test$ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -days 30 \ -keyout certs/example.key -out certs/example.crt \ -subj "/CN=example.com" -addext "subjectAltName=DNS:example.com"[2] 내용을 확인합니다. 자체 서명이므로 subject 와 issuer 가 같습니다.
$ openssl x509 -in certs/example.crt -noout -subject -issuer -dates -ext subjectAltNamesubject=CN = example.comissuer=CN = example.comnotBefore=Oct 19 05:39:24 2026 GMTnotAfter=Nov 18 05:39:24 2026 GMTX509v3 Subject Alternative Name: DNS:example.com[3] server 블록에 listen … ssl 과 인증서·키 경로를 넣습니다. 시험용이라 높은 포트를 씁니다. 키 파일은 -nodes 로 만들어 -rw------- 권한이므로 Nginx 를 띄우는 사용자가 읽을 수 있어야 합니다.
server { listen 18843 ssl; server_name example.com; ssl_certificate /srv/tls-test/certs/example.crt; ssl_certificate_key /srv/tls-test/certs/example.key; root /srv/tls-test/www;}[4] 설정을 검사하고 띄웁니다.
# nginx -tnginx: configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful# systemctl reload nginx[5] 검증을 켠 채로 curl 을 부릅니다. example.com 은 시험 주소로 연결하도록 --resolve 를 씁니다. 종료 코드는 60 입니다.
$ curl --resolve example.com:18843:127.0.0.1 https://example.com:18843/curl: (60) SSL certificate problem: self-signed certificateMore details here: https://curl.se/docs/sslcerts.html이 오류는 Nginx 설정이 틀렸다는 뜻이 아닙니다. 연결은 되었고, 서버가 보낸 인증서를 curl 이 믿는 CA 목록에서 찾지 못한 것입니다.
[6] -k 로 검증을 건너뛰면 응답이 옵니다. -w 의 ssl_verify_result 로 검증이 실제로 건너뛰어졌는지 볼 수 있습니다. 18 은 OpenSSL 의 self-signed certificate 코드입니다.
$ curl -sS -k --resolve example.com:18843:127.0.0.1 https://example.com:18843/ok$ curl -sS -o /dev/null -w '%{http_code} verify=%{ssl_verify_result}\n' -k \ --resolve example.com:18843:127.0.0.1 https://example.com:18843/200 verify=18[7] 검증을 끄지 않고 통과시키려면 그 인증서를 직접 믿게 합니다. --cacert 에 만든 인증서를 주면 verify=0 으로 끝납니다.
$ curl -sS -o /dev/null -w '%{http_code} verify=%{ssl_verify_result}\n' \ --cacert certs/example.crt --resolve example.com:18843:127.0.0.1 https://example.com:18843/200 verify=0[8] 인증서의 이름과 접속 주소가 다르면 --cacert 를 줘도 실패합니다. 위 인증서에는 DNS:example.com 만 있으므로 IP 로 접속하면 아래 문구가 나옵니다.
$ curl --cacert certs/example.crt https://127.0.0.1:18843/curl: (60) SSL: no alternative certificate subject name matches target host name '127.0.0.1'Nginx 로그를 브라우저에서 바로 분석 ↗ — 아무것도 올라가지 않습니다.
인증서(PEM · X.509) 풀기 도구로 바로 확인 ↗ — 브라우저 안에서 계산합니다.