1+ # /etc/nginx/sites-enabled/toolshed.conf
2+
3+ # Trust all proxies (adjust as needed)
4+ set_real_ip_from 0.0.0.0/0;
5+ real_ip_header X-Forwarded-For;
6+ real_ip_recursive on;
7+
8+ # Map backend_choice to just the port number for the header.
9+ map $backend_choice $served_from {
10+ "127.0.0.1:8001" "8001";
11+ "127.0.0.1:8002" "8002";
12+ "127.0.0.1:8003" "8003";
13+ "127.0.0.1:8004" "8004";
14+ "127.0.0.1:8005" "8005";
15+ }
16+
17+ # Use the client's IP as the sticky value.
18+ map $remote_addr $sticky_value {
19+ default $remote_addr;
20+ }
21+
22+ # Deterministically assign a backend server based on the client's IP.
23+ split_clients "$sticky_value" $backend_choice {
24+ # NOTE: 8000 is running, but reserved for "internal" use, where our codebase
25+ # makes requests to localhost:8000.
26+ # 20% 127.0.0.1:8000;
27+ 20% 127.0.0.1:8001;
28+ 20% 127.0.0.1:8002;
29+ 20% 127.0.0.1:8003;
30+ 20% 127.0.0.1:8004;
31+ 20% 127.0.0.1:8005;
32+ }
33+
34+ # Map for handling the upgrade header.
35+ map $http_upgrade $connection_upgrade {
36+ default Upgrade;
37+ '' close;
38+ }
39+
40+ server {
41+ listen 8080;
42+ server_name localhost;
43+
44+ location / {
45+ add_header X-Served-From $served_from always;
46+ proxy_set_header X-Forwarded-For $remote_addr;
47+ proxy_set_header X-Real-IP $remote_addr;
48+ proxy_set_header Host $host;
49+ proxy_set_header Tailscale-User-Login $http_tailscale_user_login;
50+ proxy_pass http://$backend_choice;
51+ }
52+
53+ location /api/storage/memory {
54+ proxy_pass http://$backend_choice;
55+ proxy_http_version 1.1;
56+ proxy_set_header Upgrade $http_upgrade;
57+ proxy_set_header Connection $connection_upgrade;
58+ proxy_set_header Host $host;
59+ proxy_set_header X-Real-IP $remote_addr;
60+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
61+ proxy_set_header Tailscale-User-Login $http_tailscale_user_login;
62+
63+ # Increase timeouts for long-lived WebSocket connections.
64+ proxy_read_timeout 86400;
65+ proxy_send_timeout 86400;
66+ }
67+
68+ # Expose Nginx status at /_nginx.
69+ location /_nginx {
70+ # Enable the stub_status module.
71+ stub_status;
72+
73+ # Optionally, restrict access to this endpoint.
74+ # For example, only allow local connections:
75+ # Allow all devices on the Tailscale network.
76+ allow 100.64.0.0/10;
77+ allow 127.0.0.1;
78+ allow ::1;
79+ deny all;
80+ }
81+ }
0 commit comments