|
| 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