nginx:config:https

HTTPS

NGINX에서 TLS(HTTPS) server block을 구성할 때 자주 보는 핵심 directive와 안전한 기본 예시를 정리한다.

  • HTTPS는 보통 listen 443 ssl 과 인증서 경로, TLS 정책, redirect 정책을 함께 다룬다.
  • 설정 저장 후에는 nginx -t 로 먼저 검증하고, 이상이 없을 때만 reload 하는 편이 안전하다.
  • 인증서 파일과 private key는 권한을 최소화하고, 위키에는 실제 비밀값을 기록하지 않는다.
  • listen 443 ssl: HTTPS 수신 포트와 SSL 사용 여부를 지정한다.
  • http2: 같은 listen 줄에 붙여 HTTP/2 활성화를 지정할 때 자주 쓴다.
  • server_name: 인증서 SAN/CN과 맞는 hostname을 지정한다.
  • ssl_certificate: 공개 인증서(fullchain 포함)를 가리킨다.
  • ssl_certificate_key: private key 경로를 지정한다.
  • ssl_protocols: 허용할 TLS 버전을 제한한다. 일반적으로 구버전 TLS는 제외한다.
  • ssl_ciphers: 사용할 cipher policy를 지정한다. 배포판 기본 정책을 따르는 환경도 많다.
  • ssl_prefer_server_ciphers: 서버 우선 cipher 선택 여부다.
  • ssl_session_cache, ssl_session_timeout: TLS session 재사용 관련 설정이다.
  • add_header Strict-Transport-Security …: HSTS를 활성화해 브라우저가 HTTPS를 강제하게 한다.
  • return 301 https://$host$request_uri: HTTP 요청을 HTTPS로 넘길 때 자주 쓰는 redirect 패턴이다.
HSTS는 한번 배포되면 브라우저에 오래 남을 수 있다. 인증서 갱신, 서브도메인 적용 범위, 롤백 가능성을 먼저 검토하고 적용하는 편이 안전하다.
  • 기본 TLS server block
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com www.example.com;
 
    root /srv/www/example;
    index index.html index.htm;
 
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_prefer_server_ciphers on;
 
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
 
    location / {
        try_files $uri $uri/ =404;
    }
}
  • HTTP에서 HTTPS로 redirect
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
 
    return 301 https://$host$request_uri;
}
  • server_name 과 인증서 대상 이름이 다르면 브라우저 경고가 발생할 수 있다.
  • fullchain.pemprivkey.pem 경로는 Let's Encrypt 계열에서 흔한 예시일 뿐이며, 실제 경로는 배포 환경에 맞춰 다를 수 있다.
  • reverse proxy 환경이라면 HTTPS 종료 지점을 어디에 둘지 먼저 정하고, upstream과의 통신 정책을 분리해서 본다.
  • 테스트나 임시 인증서로 먼저 확인하더라도 운영 전환 전에는 강제 redirect, HSTS, 자동 갱신 경로까지 점검하는 편이 좋다.
nginx -t
nginx -s reload
  • codex:: 2026-07-15 Expanded the HTTPS config page with core directive explanations, redirect example, and TLS deployment notes.
  • /home/u613600155/domains/cli.zerotymer.net/public_html/data/pages/nginx/config/https.txt
  • 마지막으로 수정됨: 2026/07/15 13:33
  • (바깥 편집)