Next.js HTTPS 적용하기

곽태욱·2022년 3월 2일
0

Install nginx

sudo apt update
sudo apt install nginx
sudo ufw app list
sudo ufw allow 'Nginx HTTP'
systemctl start nginx

Configure nginx

cd /etc/nginx/sites-available
vi 도메인
# *q is our domain, replace port 3000 with your port number
server {
  listen 80;
  listen [::]:80;

  root /var/www/html;
  index index.html index.htm index.nginx-debian.html;

  server_name 도메인 www.도메인;

  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }

  # for letsencrypt
  location ~ /.well-known {
    allow all;
  }
}

/etc/nginx/sites-available 경로에 도메인 파일을 만들어서 위 내용을 적절히 바꿔 입력해줍니다.

sudo ln -s /etc/nginx/sites-available/도메인 /etc/nginx/sites-enabled/도메인
nginx -t
service nginx restart

Install certbot

sudo apt update && sudo apt install certbot python3-certbot-nginx

Configure certbot

certbot --nginx -d 도메인 -d www.도메인
certbot certonly --standalone --preferred-challenges http -d 도메인
certbot renew --dry-run

Auto renew certificate

crontab -e
0 12 * * * /usr/bin/certbot renew --quiet

매일 정오에 서버의 인증서가 다음 30일 이내에 만료되는지 확인하고 만료되면 갱신하는 명령을 실행합니다. --quiet 은 certbot이 출력을 생성하지 않게 하는 옵션입니다.

profile
이유와 방법을 알려주는 메모장 겸 블로그. 블로그 내용에 대한 토의나 질문은 언제나 환영합니다.

0개의 댓글