Skip to content

Commit 5aa6070

Browse files
authored
Merge pull request #201 from hubmapconsortium/jpuerto/nginx-passthrough
Jpuerto/nginx passthrough
2 parents b68d621 + 8aecf0b commit 5aa6070

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

docker/user_workspaces_server/nginx/conf.d/passthrough.conf

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ server {
22
listen 5050;
33
client_max_body_size 100M;
44

5-
location / {
6-
# This would be where we do the proxying through to the appropriate machines.
5+
# Proxy admin route back to web
6+
location /admin {
77
proxy_pass http://web:5050;
88
proxy_http_version 1.1;
99
proxy_set_header Upgrade $http_upgrade;
@@ -13,4 +13,25 @@ server {
1313
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1414
proxy_set_header X-Forwarded-Host $server_name;
1515
}
16+
17+
# Passthrough route should just route traffic to the appropriate place.
18+
location ~ ^/passthrough/([^/]+)/(\d+)/(.*)$ {\
19+
# Extract hostname, port, and path using capture groups
20+
set $target_host $1;
21+
set $target_port $2;
22+
set $target_path /$3;
23+
24+
proxy_pass http://$target_host:$target_port/passthrough/$target_host/$target_port$target_path$is_args$args;
25+
26+
# Forward headers to support WebSockets
27+
proxy_http_version 1.1;
28+
proxy_set_header Upgrade $http_upgrade;
29+
proxy_set_header Connection "upgrade";
30+
31+
# Preserve original headers
32+
proxy_set_header Host $host;
33+
proxy_set_header X-Real-IP $remote_addr;
34+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
35+
proxy_set_header X-Forwarded-Proto $scheme;
36+
}
1637
}

src/user_workspaces_server/templates/script_templates/jupyter_lab_template.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ if ${VERSION:0:1} < 3:
132132
c.NotebookApp.allow_origin = '*'
133133
c.NotebookApp.notebook_dir = "{{ workspace_full_path }}"
134134
c.NotebookApp.disable_check_xsrf = True
135-
c.NotebookApp.base_url = "/passthrough/$(hostname)/{{ job_id }}"
135+
c.NotebookApp.base_url = "/passthrough/$(hostname)/${PORT}"
136136
c.NotebookApp.port = ${PORT}
137137
else:
138138
c.ServerApp.ip = '*'
139139
c.ServerApp.open_browser = False
140140
c.ServerApp.allow_origin = '*'
141141
c.ServerApp.root_dir = "{{ workspace_full_path }}"
142142
c.ServerApp.disable_check_xsrf = True
143-
c.ServerApp.base_url = "/passthrough/$(hostname)/{{ job_id }}"
143+
c.ServerApp.base_url = "/passthrough/$(hostname)/${PORT}"
144144
c.ServerApp.port = ${PORT}
145145
EOL
146146
)

src/user_workspaces_server/urls.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
from django.urls import include, path
1818

1919
from . import ws_consumers
20-
from .views import (
20+
from .views import ( # passthrough_view,
2121
job_type_view,
2222
job_view,
2323
parameter_view,
24-
passthrough_view,
2524
shared_workspace_view,
2625
status_view,
2726
user_view,
@@ -65,18 +64,18 @@
6564
path("", parameter_view.ParameterView.as_view(), name="parameters"),
6665
]
6766

68-
passthrough_view_patterns = [
69-
path(
70-
"<str:hostname>/<int:job_id>/",
71-
passthrough_view.PassthroughView.as_view(),
72-
name="passthrough",
73-
),
74-
path(
75-
"<str:hostname>/<int:job_id>/<path:remainder>",
76-
passthrough_view.PassthroughView.as_view(),
77-
name="passthrough_remainder",
78-
),
79-
]
67+
# passthrough_view_patterns = [
68+
# path(
69+
# "<str:hostname>/<int:job_id>/",
70+
# passthrough_view.PassthroughView.as_view(),
71+
# name="passthrough",
72+
# ),
73+
# path(
74+
# "<str:hostname>/<int:job_id>/<path:remainder>",
75+
# passthrough_view.PassthroughView.as_view(),
76+
# name="passthrough_remainder",
77+
# ),
78+
# ]
8079

8180
user_view_patterns = [
8281
path(
@@ -109,7 +108,7 @@
109108
path("workspaces/", include(workspace_view_patterns)),
110109
path("jobs/", include(job_view_patterns)),
111110
path("job_types/", include(job_type_view_patterns)),
112-
path("passthrough/", include(passthrough_view_patterns)),
111+
# path("passthrough/", include(passthrough_view_patterns)),
113112
path("parameters/", include(parameter_view_patterns)),
114113
path("users/", include(user_view_patterns)),
115114
path("shared_workspaces/", include(shared_workspace_view_patterns)),

0 commit comments

Comments
 (0)