mirror of
https://github.com/KohakuBlueleaf/KohakuHub.git
synced 2026-03-11 17:34:08 -05:00
106 lines
4.1 KiB
Plaintext
106 lines
4.1 KiB
Plaintext
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
# Allow large client request bodies for file uploads in commits
|
|
client_max_body_size 100G;
|
|
|
|
# Root directory for the built Vue.js application
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# =================================================================
|
|
# API PROXY RULES
|
|
#
|
|
# These specific locations are evaluated BEFORE the general SPA rule.
|
|
# The order of these proxy rules matters - most specific first.
|
|
# =================================================================
|
|
|
|
# 1. API endpoints (all routes under /api/)
|
|
# Covers: /api/auth/*, /api/repos/*, /api/models/*, /api/datasets/*,
|
|
# /api/spaces/*, /api/users/*, /api/organizations/*, /api/whoami-v2, etc.
|
|
location /api/ {
|
|
proxy_pass http://hub-api:48888;
|
|
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;
|
|
}
|
|
|
|
# 2. Admin API endpoints (mounted at /admin/api/)
|
|
# Covers: /admin/api/users/*, /admin/api/quota/*, /admin/api/stats
|
|
location /admin/api/ {
|
|
proxy_pass http://hub-api:48888;
|
|
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;
|
|
}
|
|
|
|
# 3. Organization API endpoints (mounted at /org/)
|
|
# Covers: /org/create, /org/{name}, /org/{name}/members, /org/users/{username}/orgs
|
|
location /org/ {
|
|
proxy_pass http://hub-api:48888;
|
|
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;
|
|
}
|
|
|
|
# 4. Git LFS endpoints
|
|
# Covers: /{type}s/{namespace}/{name}.git/info/lfs/* and /{namespace}/{name}.git/info/lfs/*
|
|
location ~ \.git/info/lfs/ {
|
|
proxy_pass http://hub-api:48888;
|
|
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;
|
|
# Important for large file uploads
|
|
proxy_request_buffering off;
|
|
client_body_buffer_size 128k;
|
|
}
|
|
|
|
# 5. Public file resolution routes (no /api prefix)
|
|
# These are public-facing download endpoints
|
|
# Pattern: /{type}s/{namespace}/{name}/resolve/{revision}/{path}
|
|
location ~ ^/(models|datasets|spaces)/[^/]+/[^/]+/resolve/ {
|
|
proxy_pass http://hub-api:48888;
|
|
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;
|
|
}
|
|
|
|
# 6. Legacy public file resolution route (no /api prefix, no type prefix)
|
|
# Pattern: /{namespace}/{name}/resolve/{revision}/{path}
|
|
# Must come AFTER the specific routes to avoid catching frontend routes
|
|
location ~ ^/[^/]+/[^/]+/resolve/ {
|
|
proxy_pass http://hub-api:48888;
|
|
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;
|
|
}
|
|
|
|
|
|
# =================================================================
|
|
# ADMIN FRONTEND SPA
|
|
#
|
|
# Serve admin portal at /admin (before main SPA fallback)
|
|
# =================================================================
|
|
location /admin {
|
|
alias /usr/share/nginx/html-admin/;
|
|
try_files $uri $uri/ /admin/index.html;
|
|
}
|
|
|
|
# =================================================================
|
|
# MAIN FRONTEND SINGLE PAGE APP (SPA)
|
|
#
|
|
# This is the final fallback. If no API rule above matched,
|
|
# Nginx assumes it's a frontend route and serves the main SPA.
|
|
# =================================================================
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
}
|