#!/bin/bash
cat > /etc/nginx/sites-enabled/default << 'EOF'
server {
    server_name webdav.4fsake.me;

    location / {
        proxy_pass http://localhost:8888/;
        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_buffering off;
    }

    listen [::]:443 ssl;
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/webdav.4fsake.me/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/webdav.4fsake.me/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

server {
    if ($host = webdav.4fsake.me) {
        return 301 https://$host$request_uri;
    }

    listen 80;
    listen [::]:80;
    server_name webdav.4fsake.me;
    return 404;
}
EOF

nginx -t && systemctl reload nginx
echo "완료"
