Nginx – 转发绝对url的请求

我正在寻求代理mapquest OSM瓷砖,所以我可以通过SSL为我的用户提供服务。 这是我的nginxconfiguration看起来像:

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

因此,如果http://otile1.mqcdn.com/tiles/1.0.0/osm/14/3678/6230.png中存在地图图块,我想通过https://app.example.com/tiles访问它/1.0.0/osm/14/3678/6230.png 。

目前,我收到了一个“无效的url”错误。

编辑:

我也考虑过这样做:

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

但是这将redirect到最终的url而不是代理请求。 有没有办法隐藏客户端的最终URL?

也许你忘记了proxy_set_header Host "otile1.mqcdn.com";

请注意,所有上游服务器都必须能够接受此类Host标头,因为这些标头是有效且适当的。

如果你没有手动定义一个Host头,那么可能没有主机头将被提供给上游。

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

如果使用upstream模块,则文档不完全清楚Host默认设置的内容; 但是您的情况可能听起来像某些function目前可能会丢失!