Skip to content

Commit 2e198c6

Browse files
committed
proxy: Access CMS instances through subpaths
Expose CogStack ModelServe instances (services listening on port 8000) as subpaths through the proxy, alleviating the need to hardcode host port mappings in the client applications. Instead, requests to `/cms/<service>` are forwarded to `<service>:8000` internally using the Docker DNS resolver. This also allows us to access user-deployed CMS instances through the proxy without any configuration changes. The rest of the services included in the stack (e.g. Grafana, MLflow) are still available through their respective host port mappings. Even though efforts were made to integrate them as subpaths, they are not fully supported at this stage. More specifically, while accessing exact paths through their APIs might be possible, accessing their web interfaces when using subpaths is problematic, due to the way these external services handle redirects. Even though we employ certain heuristics to rewrite local URLs we can't account for all possible cases, e.g. local paths in HTML responses. This is a known limitation that should be addressed in future iterations. Signed-off-by: Phoevos Kalemkeris <[email protected]>
1 parent 2c18a2f commit 2e198c6

File tree

7 files changed

+79
-204
lines changed

7 files changed

+79
-204
lines changed

docker-compose-proxy.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ services:
2323
- http_proxy=$HTTP_PROXY
2424
- https_proxy=$HTTPS_PROXY
2525
- no_proxy=localhost
26+
expose:
27+
- 443
2628
ports:
27-
- 28180:28180 # medcat-snomed
28-
- 28181:28181 # medcat-icd10
29-
# - 28182:28182 # de-identification (deprecated)
30-
- 28183:28183 # medcat-deid (anoncat)
31-
- 28184:28184 # medcat-umls
32-
- 28185:28185 # huggingface-ner
29+
- 443:443 # cms
3330
- 28199:28199 # minio
3431
- 28200:28200 # mlflow-ui
3532
- 28201:28201 # prometheus
@@ -43,4 +40,4 @@ services:
4340

4441
networks:
4542
cogstack-model-serve_cms:
46-
external: true
43+
external: true

docker/nginx/etc/nginx/nginx.conf

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,85 @@ http {
1616
client_max_body_size 500M;
1717

1818
server {
19+
listen 443 ssl http2;
20+
listen [::]:443 ssl http2;
21+
server_name localhost;
22+
23+
add_header Strict-Transport-Security "max-age=31536000" always;
24+
25+
ssl_session_cache shared:SSL:20m;
26+
ssl_session_timeout 10m;
27+
ssl_protocols TLSv1.2 TLSv1.3;
28+
ssl_prefer_server_ciphers on;
29+
ssl_ciphers "ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!ADH:!AECDH:!MD5;";
30+
ssl_stapling on;
31+
ssl_stapling_verify on;
32+
33+
resolver 8.8.8.8 8.8.4.4;
34+
35+
ssl_certificate /etc/nginx/root-ca.pem;
36+
ssl_certificate_key /etc/nginx/root-ca.key;
37+
38+
access_log /var/log/nginx/access.log;
39+
error_log /var/log/nginx/error.log;
40+
1941
location /health {
2042
include cors.conf;
2143
access_log off;
2244
return 200 "OK\n";
2345
}
46+
47+
location ~ ^/cms/(?<service>[^/]+)(?<subpath>/.*)?$ {
48+
include cors.conf;
49+
resolver 127.0.0.11 valid=30s;
50+
set $upstream $service:8000;
51+
52+
# FIXME: Access web interfaces (e.g. Grafana, MLflow) through subpaths on the proxy.
53+
# The following services only work when accessed directly through their respective APIs.
54+
# Attempting to access their UI through the proxy leads to issues due to the way they
55+
# handle redirects (even though we can employ certain heuristics to rewrite local URLs
56+
# we can't account for all possible cases, e.g. local paths in HTML responses). As a
57+
# result, accessing these web intercases through the proxy is only possible using the
58+
# available host port mappings instead of the subpaths under /cms for the time being.
59+
if ($service = "grafana") {
60+
set $upstream $service:3000;
61+
}
62+
63+
if ($service = "graylog") {
64+
set $upstream $service:9000;
65+
}
66+
67+
if ($service = "minio") {
68+
set $upstream $service:9001;
69+
}
70+
71+
if ($service = "mlflow-ui") {
72+
set $upstream $service:5000;
73+
}
74+
75+
if ($service = "prometheus") {
76+
set $upstream $service:9090;
77+
}
78+
79+
proxy_pass http://$upstream$subpath;
80+
81+
proxy_redirect http://$upstream$subpath $scheme://$host/cms/$service$subpath;
82+
proxy_redirect http://$upstream/ $scheme://$host/cms/$service/;
83+
proxy_redirect http://$upstream $scheme://$host/cms/$service;
84+
proxy_redirect / $scheme://$host/cms/$service/;
85+
86+
proxy_set_header Host $host;
87+
proxy_set_header X-Real-IP $remote_addr;
88+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
89+
proxy_set_header X-Forwarded-Proto $scheme;
90+
91+
error_page 502 503 504 = @fallback;
92+
}
93+
94+
location @fallback {
95+
return 503 "Service is temporarily unavailable. Please try again later.";
96+
}
2497
}
2598

26-
include sites-enabled/medcat-snomed;
27-
include sites-enabled/medcat-icd10;
28-
include sites-enabled/medcat-deid;
29-
include sites-enabled/medcat-umls;
30-
include sites-enabled/huggingface-ner;
31-
include sites-enabled/mlflow-ui;
32-
include sites-enabled/minio;
33-
include sites-enabled/prometheus;
34-
include sites-enabled/grafana;
35-
include sites-enabled/graylog;
36-
}
99+
include sites-enabled/*;
100+
}

docker/nginx/etc/nginx/sites-enabled/huggingface-ner

Lines changed: 0 additions & 37 deletions
This file was deleted.

docker/nginx/etc/nginx/sites-enabled/medcat-deid

Lines changed: 0 additions & 37 deletions
This file was deleted.

docker/nginx/etc/nginx/sites-enabled/medcat-icd10

Lines changed: 0 additions & 37 deletions
This file was deleted.

docker/nginx/etc/nginx/sites-enabled/medcat-snomed

Lines changed: 0 additions & 38 deletions
This file was deleted.

docker/nginx/etc/nginx/sites-enabled/medcat-umls

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)