# HTTP to HTTPS Redirection
server {
    listen 80;
    server_name dip-zero.geumdo.net;

    # Redirect all HTTP requests to HTTPS
    return 301 https://$host$request_uri;
}

# Main HTTPS Server Block
server {
    listen 443 ssl;
    server_name dip-zero.geumdo.net;

    ssl_certificate /etc/letsencrypt/live/dip-zero.geumdo.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dip-zero.geumdo.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / {
        proxy_pass https://192.168.0.10:4444;
        proxy_set_header        Host                    $http_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;
        proxy_set_header        X-CSRF-Token            $http_x_csrf_token;  # CSRF 토큰 전달
        proxy_set_header        Cookie                  $http_cookie;  # 쿠키 전달

        ## prevent 504 timeout. default 60s;
        proxy_connect_timeout       300;
        proxy_send_timeout          300;
        proxy_read_timeout          300;
        send_timeout                300;

        # 클라이언트 요청 버퍼링 끄기
        proxy_request_buffering off;
        # 백엔드 서버 응답 버퍼링 끄기
        proxy_buffering off;       
    }
}
