-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx-base.conf.template
More file actions
115 lines (97 loc) · 4.17 KB
/
Copy pathnginx-base.conf.template
File metadata and controls
115 lines (97 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Increase server names hash bucket size for long UUIDs
server_names_hash_bucket_size 128;
# Allow larger request bodies (audio uploads, file transfers, etc.)
# Applies to all server blocks: frontend, API, and workspace subdomains
client_max_body_size 50M;
# Enable DNS resolver for dynamic container resolution
resolver 127.0.0.11 valid=30s;
# Define connection upgrade mapping for WebSockets
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream api_backend {
server server:3000;
}
# Main server for the frontend and API
server {
listen 80;
server_name ${BASE_DOMAIN};
# Frontend
location / {
root /usr/share/nginx/html/frontend;
index index.html;
try_files $uri $uri/ /index.html;
}
# API routes
location /api/ {
proxy_pass http://api_backend;
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;
}
# GIT_SERVER_PLACEHOLDER
}
# Custom workspace subdomain aliases (auto-generated by aliasesService).
# Each alias is rendered as an exact-match server_name, so it takes
# priority over the regex-based UUID routing below.
# Glob pattern makes it optional — first boot starts before the file exists.
include /etc/nginx/dynamic/aliases.conf*;
# Subdomain server for workspace applications on specific ports
# Pattern: projectid-port.domain (e.g., projectid-5000.localhost or projectid-5000.ci.infra)
# NOTE: This MUST come before the general workspace pattern to match first
server {
listen 80;
server_name "~^(?<workspace_id>[a-f0-9\-]+)-(?<app_port>[0-9]{1,5})\.${BASE_DOMAIN}$";
location / {
set $upstream workspace-$workspace_id:$app_port;
# Proxy to application running in workspace container
proxy_pass http://$upstream;
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-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Port $server_port;
# WebSocket support for applications that need it
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
proxy_send_timeout 86400;
}
}
# Catch-all: any Host header that doesn't match a more-specific
# server_name (frontend, workspace UUID, workspace port, custom alias)
# ends up here and gets a clean 404 instead of silently falling
# back to the auth-protected frontend.
server {
listen 80 default_server;
server_name _;
default_type text/plain;
return 404 "Unknown subdomain. The alias may have been deleted or was never created.\n";
}
# Subdomain server for workspace code-server instances
# Pattern: projectid.domain (e.g., projectid.localhost or projectid.ci.infra)
server {
listen 80;
server_name ~^(?<workspace_id>[a-f0-9\-]+)\.${BASE_DOMAIN}$;
location / {
set $upstream workspace-$workspace_id:8082;
# Proxy to code-server container
proxy_pass http://$upstream;
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-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Port $server_port;
# WebSocket support for code-server
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
proxy_send_timeout 86400;
}
}