1

I'm looking to proxy mapquest OSM tiles so I can serve them to my users via SSL. This is what my nginx config looks like:

upstream maptile_server {
    server otile1.mqcdn.com;
    server otile2.mqcdn.com;
    server otile3.mqcdn.com;
    server otile4.mqcdn.com;
}

server {

    # ...

    server_name app.example.com;

    location /tiles {
            proxy_pass http://maptile_server;
    }
}

So if a map tile exists at http://otile1.mqcdn.com/tiles/1.0.0/osm/14/3678/6230.png, I want to access it at https://app.example.com/tiles/1.0.0/osm/14/3678/6230.png.

Currently I'm getting an "Invalid URL" error.

EDIT:

I also considered doing something like this:

location ~ /maptiles/(?<subdomain>.+)/(?<z>.+)/(?<x>.+)/(?<y>.+) {
    return http://$subdomain.mqcdn.com/tiles/1.0.0/osm/$z/$x/$y;
}

But this redirects me to the final url rather than proxying the request. Is there any way to hide the final URL from the client?

kbanman
  • 209
  • 2
  • 7

1 Answers1

2

Perhaps you are forgetting proxy_set_header Host "otile1.mqcdn.com";?

Notice that all your upstream servers will have to be capable of accepting such Host header as valid and appropriate.

If you don't manually define a Host header, then perhaps no host header will be provided to the upstream.

http://wiki.nginx.org/HttpProxyModule#proxy_set_header
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream

The documentation is not exactly clear of what Host is set to by default if the upstream module is used; but your situation may sound like some functionality might currently be missing!

cnst
  • 13,848
  • 9
  • 54
  • 76
  • This causes it to work! but since I'm using multiple upstream servers, I don't see a way to adjust the Host header based on which server nginx chooses. – kbanman Mar 07 '13 at 05:24
  • Yes, and this is already briefly addressed in my answer. In most situations, if you have multiple upstreams, then it is implied that you control all of them, and would have little trouble ensuring that they reply uniformly through a given `Host`. Else, if you have no control over them, then it is most likely that you don't really need to specify more than one upstream in the first place. :-) – cnst Mar 07 '13 at 06:02