worker_processes auto;
events { worker_connections 1024; }

http {
    include /etc/nginx/mime.types;
    
    # 인스턴스별로 계산된 포트 주입
    upstream backend_srv {
        server backend:{{BACKEND_PORT}};
    }

    upstream oathkeeper_srv {
        server oathkeeper:4455;
    }

    server {
        listen 80;
        
        # SSO 메인 도메인 및 API 처리
        location /api {
            proxy_pass http://backend_srv;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /auth {
            proxy_pass http://oathkeeper_srv;
            proxy_set_header Host $host;
        }

        location /oidc {
            proxy_pass http://oathkeeper_srv;
            proxy_set_header Host $host;
        }

        # 기본 정적 파일 (UserFront)
        location / {
            root /usr/share/nginx/html;
            try_files $uri $uri/ /index.html;
        }
    }
}
