sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx -d your_domain
sudo certbot renew --dry-run
upstream backend {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name your_domain;
# Redirect all HTTP requests to HTTPS
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name your_domain;
ssl_certificate /etc/nginx/ssl/your_domain.crt;
ssl_certificate_key /etc/nginx/ssl/your_domain.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# Tomcat service
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
return 301 https://$host$request_uri;
301 Moved Permanently는 HTTP 상태 코드로, 클라이언트에게 요청한 리소스가 영구적으로 새로운 위치로 이동됩니다.
$host: 요청된 URL의 호스트 부분을 포함합니다.(클라이언트가 요청한 호스트명이 포함)
$request_uri: 요청된 URI를 포함합니다.
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
sudo nginx -t
sudo systemctl restart nginx
sudo ufw allow 443
이제 Nginx 서버가 SSL을 사용하여 443 포트에서 통신하도록 설정되었습니다.