nginx: 정적 사이트 + SSL + HTTP→HTTPS
정적 사이트(SSG) 배포 시 가장 흔한 nginx 구성 패턴
정적 사이트를 nginx로 서빙할 때 자주 쓰는 구성입니다.
예시 설정
server {
server_name dev.playcity.kr;
root /home/ubuntu/app/dev.playcity.kr/dist;
index index.html;
location /.well-known/acme-challenge/ {
root /var/www/letsencrypt;
}
location ^~ /_astro/ {
try_files $uri =404;
expires 365d;
add_header Cache-Control "public, max-age=31536000, immutable";
}
location / {
try_files $uri $uri/ =404;
}
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/dev.playcity.kr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dev.playcity.kr/privkey.pem;
}
server {
listen 80;
server_name dev.playcity.kr;
return 301 https://$host$request_uri;
}
체크리스트
/_astro/같은 해시 자산은immutable캐시 적용/.well-known/acme-challenge/경로는 certbot용으로 열어두기- HTTP는 301로 HTTPS로 리다이렉트