# HTTPS server
server {
    listen 8100;
    server_name rogaining.sumasen.net localhost;
    
    access_log /var/log/nginx/api_access.log;
    error_log /var/log/nginx/api_error.log debug;

    root   /usr/share/nginx/html;
    index  index.html;

    # Django admin
    location ~ ^/(admin|api)/ {
        proxy_pass http://api:8000;
	proxy_http_version 1.1;
        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;
        proxy_set_header X-CSRFToken $http_x_csrf_token;

        # タイムアウト設定
        proxy_connect_timeout 300;
        proxy_send_timeout 300;
        proxy_read_timeout 300;
        send_timeout 300;
    }

    # Supervisor webapp
    location /supervisor/ {
        alias /usr/share/nginx/html/supervisor/;
        try_files $uri $uri/ /supervisor/index.html;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
    }

    location /static/ {
            proxy_pass http://api:8000;
	proxy_http_version 1.1;
        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;
        proxy_set_header X-CSRFToken $http_x_csrf_token;

        # タイムアウト設定
        proxy_connect_timeout 300;
        proxy_send_timeout 300;
        proxy_read_timeout 300;
        send_timeout 300;
    #    alias /app/static/;
    #    expires 1h;
    #    add_header Cache-Control "public, no-transform";
    }

    location = / {
        root /usr/share/nginx/html;
        index index.html;
    }

    location = /media/ {
        alias /app/media/;  # MEDIA_ROOT のパス
        expires 30d;  # キャッシュの設定
        add_header Cache-Control "public, no-transform";
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}
