Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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!

share|improve this answer
    
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 7 '13 at 5: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 7 '13 at 6:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.