Skip to content

Commit 7b99025

Browse files
committed
2 parents 2eea32d + 6f5fed7 commit 7b99025

File tree

5 files changed

+143
-5
lines changed

5 files changed

+143
-5
lines changed

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Workspaces Stack
2+
Copyright (C) 2024 Taskar Center for Accessible Technology
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ services:
105105
- traefik.http.services.osm-log-proxy.loadbalancer.server.port=80
106106

107107
osm-web:
108-
image: rtsp/lighttpd:latest
108+
image: nginx:stable-alpine
109109
depends_on:
110110
- osm-rails
111111
- osm-cgimap
112112
volumes:
113-
- ./osm-web/lighttpd.conf:/etc/lighttpd/conf.d/06-osm.conf:ro
114-
- ./osm-rails/public:/var/www/html:ro
113+
- ./osm-web/nginx.conf:/etc/nginx/conf.d/default.conf:ro
114+
- ./osm-rails/public:/usr/share/nginx/html:ro
115115
labels:
116116
- traefik.enable=true
117117
- traefik.http.routers.osm-web.rule=Host(`${WS_OSM_HOST}`)

osm-web/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM rtsp/lighttpd:latest
1+
FROM nginx:stable-alpine
22

3-
COPY lighttpd.conf /etc/lighttpd/conf.d/06-osm.conf
3+
COPY nginx.conf /etc/nginx/conf.d/default.conf

osm-web/lighttpd.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# This file is based on openstreetmap-cgimap's lighttpd configuration example:
33
# https://github.com/zerebubuth/openstreetmap-cgimap/blob/master/lighttpd.conf
44
#
5+
# We don't use lighttpd anymore. We'll keep this reference file for now. Nginx
6+
# replaced lighttpd, and a similar configuration exists in nginx.conf.
7+
#
58

69
server.reject-expect-100-with-417 = "disable"
710

osm-web/nginx.conf

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#
2+
# This file is based on openstreetmap-cgimap's lighttpd configuration example:
3+
# https://github.com/zerebubuth/openstreetmap-cgimap/blob/master/lighttpd.conf
4+
#
5+
6+
# Resolve hostnames with Docker's internal DNS resolver:
7+
resolver 127.0.0.11 ipv6=off;
8+
9+
upstream osm-rails-upstream {
10+
keepalive 4;
11+
server osm-rails:3000;
12+
}
13+
14+
# Improve support for third-party clients by enabling workspace selection using
15+
# a path prefix (/workspace/123/...). We strip the prefix for upstream services
16+
# here:
17+
#
18+
map $request_uri $mapped_request_uri {
19+
~^(/workspace/\d+)?(.*)$ $2;
20+
}
21+
22+
# Improve support for third-party clients by mapping workspace IDs from the URI
23+
# path prefix. We carry it here from a query parameter as needed:
24+
#
25+
map $http_x_workspace $mapped_workspace_id {
26+
default $http_x_workspace;
27+
"" $arg_x_workspace;
28+
}
29+
30+
# Improve support for third-party clients by mapping TDEI tokens from a request
31+
# basic authorization header or from the user information in a URI:
32+
#
33+
map $http_authorization $mapped_tdei_token {
34+
~^Basic $remote_user;
35+
~^Bearer\ (.*)$ $1;
36+
"" $remote_user;
37+
}
38+
39+
server {
40+
listen 80;
41+
server_name _;
42+
43+
set_real_ip_from 0.0.0.0/0;
44+
real_ip_header X-Forwarded-For;
45+
46+
error_page 404 /dispatch.map;
47+
48+
# This is effectively the maximum size of a dataset that we're willing to
49+
# accept when creating a workspace:
50+
#
51+
client_max_body_size 2g;
52+
53+
# Improve support for third-party clients by enabling workspace selection
54+
# using a path prefix (/workspace/123/...). We rewrite the path to remove
55+
# the prefix and carry the workspace ID to the next location context with
56+
# a query parameter:
57+
#
58+
location ~ ^/workspace/(\d+)/ {
59+
rewrite ^/workspace/(\d+)/(.*) /$2?x_workspace=$1 last;
60+
}
61+
62+
# If a request does not match an API endpoint implemented in CGImap, pass
63+
# the request to the Rails implementation:
64+
#
65+
location / {
66+
if ($request_method = GET) {
67+
rewrite ^/api/0\.6/map(\.(json|xml))?$ /dispatch.map last;
68+
rewrite ^/api/0\.6/(node|way|relation)/[0-9]+(\.(json|xml))?$ /dispatch.map last;
69+
rewrite ^/api/0\.6/(node|way|relation)/[0-9]+/history.*$ /dispatch.map last;
70+
rewrite ^/api/0\.6/(node|way|relation)/[0-9]+/[0-9]+.*$ /dispatch.map last;
71+
rewrite ^/api/0\.6/(node|way|relation)/[0-9]+/relations$ /dispatch.map last;
72+
rewrite ^/api/0\.6/node/[0-9]+/ways$ /dispatch.map last;
73+
rewrite ^/api/0\.6/(way|relation)/[0-9]+/full$ /dispatch.map last;
74+
rewrite ^/api/0\.6/changeset/[0-9]+.*$ /dispatch.map last;
75+
rewrite ^/api/0\.6/(nodes|ways|relations)$ /dispatch.map last;
76+
rewrite ^/api/0\.6/changeset/[0-9]+/download$ /dispatch.map last;
77+
}
78+
79+
if ($request_method = POST) {
80+
rewrite ^/api/0\.6/changeset/[0-9]+/upload.*$ /dispatch.map last;
81+
}
82+
83+
if ($request_method = PUT) {
84+
rewrite ^/api/0\.6/changeset/[0-9]+/close.*$ /dispatch.map last;
85+
rewrite ^/api/0\.6/changeset/[0-9]+$ /dispatch.map last;
86+
rewrite ^/api/0\.6/changeset/create.*$ /dispatch.map last;
87+
}
88+
89+
proxy_pass http://osm-rails-upstream;
90+
91+
# Some map operations may take a bit longer:
92+
proxy_read_timeout 3m;
93+
94+
proxy_set_header Host $host;
95+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
96+
proxy_set_header X-Forwarded-Proto $scheme;
97+
proxy_set_header X-Real-IP $remote_addr;
98+
99+
proxy_set_header Authorization "Bearer $mapped_tdei_token";
100+
proxy_set_header X-Workspace $mapped_workspace_id;
101+
}
102+
103+
# Handle requests for the endpoints implemented in CGImap:
104+
#
105+
location ~ \.map$ {
106+
fastcgi_pass osm-cgimap:8000;
107+
108+
# Large dataset uploads may take a long time to process
109+
fastcgi_read_timeout 3h;
110+
111+
fastcgi_param CONTENT_LENGTH $content_length;
112+
fastcgi_param QUERY_STRING $query_string;
113+
fastcgi_param REMOTE_ADDR $remote_addr;
114+
fastcgi_param REQUEST_METHOD $request_method;
115+
fastcgi_param REQUEST_URI $mapped_request_uri;
116+
117+
fastcgi_param HTTP_AUTHORIZATION "Bearer $mapped_tdei_token";
118+
fastcgi_param HTTP_X_WORKSPACE $mapped_workspace_id;
119+
}
120+
}

0 commit comments

Comments
 (0)