[MapProxy] mapproxy behind a reverse proxy and use of X-Script-Name
anne.blankert at geodan.nl
Fri Apr 5 09:04:07 PDT 2013
I've created support for a new reverse proxy header "X-Forwarded-Path"
(source code changes described below).
As far as I can see, this does not break current functionality, but adds
the possibility to fully reverse proxy MapProxy services like wms, wmts,
tms, tiles behind a reverse proxy.
Example reverse proxy settings for Apache config:
RequestHeader add X-Forwarded-Path /wms
<Location /wmts/ >
RequestHeader add X-Forwarded-Path /wmts/
<Location /wmts >
RequestHeader add X-Forwarded-Path /wmts
RequestHeader add X-Forwarded-Path /some_path/tms
RequestHeader add X-Forwarded-Path /some_other_path/tiles
To make this work, the following source changes were applied to MapProxy
4 files, base directory: /usr/local/lib/python2.7/dist-packages/mapproxy/
file 1: request/base.py, add new method to class Request(object)
forwarded_path = self.environ.get('HTTP_X_FORWARDED_PATH')
path_info = self.environ.get('PATH_INFO')
pos = path_info.rfind('tms')
if pos >= 0:
path_info = path_info[pos+3:]
path_info = ''
+ urllib.quote(forwarded_path).rstrip('/') + path_info)
file 2: service/wmts.py, replace line "md['url'] = tile_request.url" by:
md['url'] = tile_request.http.resource_url
file 3: service/wms.py, replace line "md['url'] = map_request.url" by:
md['url'] = map_request.http.resource_url
file 4: service/tile.py, replace line "md['url'] =
md['url'] = map_request.http.resource_url + path_info
On 22-3-2013 13:18, Oliver Tonnhofer wrote:
> On 21.03.2013, at 23:06, Anne Blankert wrote:
>> I had hoped that MapProxy would replace the script_name and path_info part of the URL ("/map/service") by the X-Script-Name ("/mywmsservice"). However, the X-Script-Name is not used as a replacement but as a prefix to /map/service (result: "/mywmsservice/map/service")
> MapProxy fully supports the X-Script-Name header and it will adapt the service URLs in the capabilities accordingly. The only problem is that script name refers to MapProxy itself. All /service, /demo, /tms, etc URLs are internals of the MapProxy service, these are not scripts.
>> Is there an easy way to prevent MapProxy from appending "/map/service" to the X-Script-Name in the getCapabilities output?
> No, it's not configurable, it will always be /service.
More information about the MapProxy