Skip to content

Commit db77c64

Browse files
committed
onyx
1 parent 461f0ec commit db77c64

5 files changed

Lines changed: 119 additions & 15 deletions

File tree

apps/onyx/docker-compose.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,10 @@ services:
8383

8484
web_server:
8585
image: onyxdotapp/onyx-web-server:${W9_VERSION}
86-
container_name: $W9_ID
86+
container_name: $W9_ID-web-server
8787
depends_on:
8888
- api_server
8989
restart: unless-stopped
90-
ports:
91-
- "${W9_HTTP_PORT_SET}:3000"
9290
env_file:
9391
- .env
9492
environment:
@@ -99,6 +97,30 @@ services:
9997
max-size: "50m"
10098
max-file: "6"
10199

100+
nginx:
101+
image: nginx:1.25.5-alpine
102+
container_name: $W9_ID
103+
restart: unless-stopped
104+
env_file:
105+
- .env
106+
depends_on:
107+
- api_server
108+
- web_server
109+
ports:
110+
- "${W9_HTTP_PORT_SET}:80"
111+
volumes:
112+
- ./src:/etc/nginx/conf.d
113+
command: >
114+
/bin/sh -c "dos2unix /etc/nginx/conf.d/run-nginx.sh 2>/dev/null || true
115+
&& /etc/nginx/conf.d/run-nginx.sh app.conf.template"
116+
environment:
117+
- DOMAIN=${W9_DOMAIN}
118+
logging:
119+
driver: json-file
120+
options:
121+
max-size: "50m"
122+
max-file: "6"
123+
102124
relational_db:
103125
image: postgres:15.2-alpine
104126
container_name: $W9_ID-postgresql

apps/onyx/src/app.conf.template

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
# Override log format to include request latency
1+
# Log format to include request latency
22
log_format custom_main '$remote_addr - $remote_user [$time_local] "$request" '
33
'$status $body_bytes_sent "$http_referer" '
44
'"$http_user_agent" "$http_x_forwarded_for" '
55
'rt=$request_time';
66

7+
# Map X-Forwarded-Proto or fallback to $scheme
8+
map $http_x_forwarded_proto $forwarded_proto {
9+
default $http_x_forwarded_proto;
10+
"" $scheme;
11+
}
12+
13+
# Map X-Forwarded-Host or fallback to $host
14+
map $http_x_forwarded_host $forwarded_host {
15+
default $http_x_forwarded_host;
16+
"" $host;
17+
}
18+
19+
# Map X-Forwarded-Port or fallback to server port
20+
map $http_x_forwarded_port $forwarded_port {
21+
default $http_x_forwarded_port;
22+
"" $server_port;
23+
}
24+
725
upstream api_server {
826
# fail_timeout=0 means we always retry an upstream even if it failed
927
# to return a good HTTP response
@@ -12,22 +30,26 @@ upstream api_server {
1230
#server unix:/tmp/gunicorn.sock fail_timeout=0;
1331

1432
# for a TCP configuration
15-
# TODO: use gunicorn to manage multiple processes
16-
server ${W9_ID}-api-server:8080 fail_timeout=0;
33+
server ${ONYX_BACKEND_API_HOST}:8080 fail_timeout=0;
1734
}
1835

1936
upstream web_server {
20-
server ${W9_ID}-web-server:3000 fail_timeout=0;
37+
server ${ONYX_WEB_SERVER_HOST}:3000 fail_timeout=0;
2138
}
2239

40+
# Conditionally include MCP upstream configuration
41+
include /etc/nginx/conf.d/mcp_upstream.conf.inc;
42+
2343
server {
24-
listen 80;
25-
server_name ${DOMAIN};
44+
listen 80 default_server;
2645

2746
client_max_body_size 5G; # Maximum upload size
2847

2948
access_log /var/log/nginx/access.log custom_main;
3049

50+
# Conditionally include MCP location configuration
51+
include /etc/nginx/conf.d/mcp.conf.inc;
52+
3153
# Match both /api/* and /openapi.json in a single rule
3254
location ~ ^/(api|openapi.json)(/.*)?$ {
3355
# Rewrite /api prefixed matched paths
@@ -36,14 +58,20 @@ server {
3658
# misc headers
3759
proxy_set_header X-Real-IP $remote_addr;
3860
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
39-
proxy_set_header X-Forwarded-Proto $scheme;
40-
proxy_set_header X-Forwarded-Host $host;
61+
proxy_set_header X-Forwarded-Proto $forwarded_proto;
62+
proxy_set_header X-Forwarded-Host $forwarded_host;
63+
proxy_set_header X-Forwarded-Port $forwarded_port;
4164
proxy_set_header Host $host;
4265

4366
# need to use 1.1 to support chunked transfers
4467
proxy_http_version 1.1;
4568
proxy_buffering off;
4669

70+
# timeout settings
71+
proxy_connect_timeout ${NGINX_PROXY_CONNECT_TIMEOUT}s;
72+
proxy_send_timeout ${NGINX_PROXY_SEND_TIMEOUT}s;
73+
proxy_read_timeout ${NGINX_PROXY_READ_TIMEOUT}s;
74+
4775
# we don't want nginx trying to do something clever with
4876
# redirects, we set the Host: header above already.
4977
proxy_redirect off;
@@ -54,12 +82,18 @@ server {
5482
# misc headers
5583
proxy_set_header X-Real-IP $remote_addr;
5684
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
57-
proxy_set_header X-Forwarded-Proto $scheme;
58-
proxy_set_header X-Forwarded-Host $host;
85+
proxy_set_header X-Forwarded-Proto $forwarded_proto;
86+
proxy_set_header X-Forwarded-Host $forwarded_host;
87+
proxy_set_header X-Forwarded-Port $forwarded_port;
5988
proxy_set_header Host $host;
6089

6190
proxy_http_version 1.1;
6291

92+
# timeout settings
93+
proxy_connect_timeout ${NGINX_PROXY_CONNECT_TIMEOUT}s;
94+
proxy_send_timeout ${NGINX_PROXY_SEND_TIMEOUT}s;
95+
proxy_read_timeout ${NGINX_PROXY_READ_TIMEOUT}s;
96+
6397
# we don't want nginx trying to do something clever with
6498
# redirects, we set the Host: header above already.
6599
proxy_redirect off;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# MCP Server location configuration
2+
location /mcp {
3+
proxy_set_header X-Real-IP $remote_addr;
4+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
5+
proxy_set_header X-Forwarded-Proto $scheme;
6+
proxy_set_header X-Forwarded-Host $host;
7+
proxy_set_header Host $host;
8+
9+
proxy_http_version 1.1;
10+
proxy_buffering off;
11+
12+
proxy_redirect off;
13+
proxy_pass http://mcp_server;
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# MCP Server upstream configuration
2+
upstream mcp_server {
3+
server ${ONYX_MCP_SERVER_HOST}:8090 fail_timeout=0;
4+
}

apps/onyx/src/run-nginx.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# fill in the template
2-
envsubst '$DOMAIN $SSL_CERT_FILE_NAME $SSL_CERT_KEY_FILE_NAME $W9_ID' < "/etc/nginx/conf.d/$1" > /etc/nginx/conf.d/app.conf
2+
export ONYX_BACKEND_API_HOST="${ONYX_BACKEND_API_HOST:-${W9_ID}-api-server}"
3+
export ONYX_WEB_SERVER_HOST="${ONYX_WEB_SERVER_HOST:-${W9_ID}-web-server}"
4+
export ONYX_MCP_SERVER_HOST="${ONYX_MCP_SERVER_HOST:-mcp_server}"
5+
6+
export SSL_CERT_FILE_NAME="${SSL_CERT_FILE_NAME:-ssl.crt}"
7+
export SSL_CERT_KEY_FILE_NAME="${SSL_CERT_KEY_FILE_NAME:-ssl.key}"
8+
9+
# Nginx timeout settings (in seconds)
10+
export NGINX_PROXY_CONNECT_TIMEOUT="${NGINX_PROXY_CONNECT_TIMEOUT:-300}"
11+
export NGINX_PROXY_SEND_TIMEOUT="${NGINX_PROXY_SEND_TIMEOUT:-300}"
12+
export NGINX_PROXY_READ_TIMEOUT="${NGINX_PROXY_READ_TIMEOUT:-300}"
13+
14+
echo "Using API server host: $ONYX_BACKEND_API_HOST"
15+
echo "Using web server host: $ONYX_WEB_SERVER_HOST"
16+
echo "Using MCP server host: $ONYX_MCP_SERVER_HOST"
17+
echo "Using nginx proxy timeouts - connect: ${NGINX_PROXY_CONNECT_TIMEOUT}s, send: ${NGINX_PROXY_SEND_TIMEOUT}s, read: ${NGINX_PROXY_READ_TIMEOUT}s"
18+
19+
envsubst '$DOMAIN $SSL_CERT_FILE_NAME $SSL_CERT_KEY_FILE_NAME $ONYX_BACKEND_API_HOST $ONYX_WEB_SERVER_HOST $ONYX_MCP_SERVER_HOST $NGINX_PROXY_CONNECT_TIMEOUT $NGINX_PROXY_SEND_TIMEOUT $NGINX_PROXY_READ_TIMEOUT' < "/etc/nginx/conf.d/$1" > /etc/nginx/conf.d/app.conf
20+
21+
# Conditionally create MCP server configuration
22+
if [ "${MCP_SERVER_ENABLED}" = "True" ] || [ "${MCP_SERVER_ENABLED}" = "true" ]; then
23+
echo "MCP server is enabled, creating MCP configuration..."
24+
envsubst '$ONYX_MCP_SERVER_HOST' < "/etc/nginx/conf.d/mcp_upstream.conf.inc.template" > /etc/nginx/conf.d/mcp_upstream.conf.inc
25+
envsubst '$ONYX_MCP_SERVER_HOST' < "/etc/nginx/conf.d/mcp.conf.inc.template" > /etc/nginx/conf.d/mcp.conf.inc
26+
else
27+
echo "MCP server is disabled, removing MCP configuration..."
28+
# Leave empty placeholder files so nginx includes do not fail
29+
# These files are empty because MCP server is disabled
30+
echo "# Empty file - MCP server is disabled" > /etc/nginx/conf.d/mcp_upstream.conf.inc
31+
echo "# Empty file - MCP server is disabled" > /etc/nginx/conf.d/mcp.conf.inc
32+
fi
333

434
# wait for the api_server to be ready
535
echo "Waiting for API server to boot up; this may take a minute or two..."
@@ -10,7 +40,7 @@ echo
1040

1141
while true; do
1242
# Use curl to send a request and capture the HTTP status code
13-
status_code=$(curl -o /dev/null -s -w "%{http_code}\n" "http://${W9_ID}-api-server:8080/health")
43+
status_code=$(curl -o /dev/null -s -w "%{http_code}\n" "http://${ONYX_BACKEND_API_HOST}:8080/health")
1444

1545
# Check if the status code is 200
1646
if [ "$status_code" -eq 200 ]; then

0 commit comments

Comments
 (0)