[squid-users] http host rewrite for origin (reverse proxy)

Amos Jeffries squid3 at treenet.co.nz
Wed Mar 9 14:43:53 UTC 2016


On 10/03/2016 3:29 a.m., Tomas Mozes wrote:
> 
> Hello Amos,
> the origin server has multiple virtual hosts configured, so if it does not
> receive the Host: header by which it is configured (like storage.example.com),
> it will emit a 404.
> 
> Currently, this does the following. The clients requests:
> GET /test.txt HTTP/1.1
> Host: cdn.example.com
> 
> This comes to squid, it will then send the same request to the origin:
> GET http://cdn.example.com/test.txt HTTP/1.1
> Host: cdn.example.com
> 
> The result is a 404. I would need squid to alter the Host: to
> storage.example.com. Is that possible?

It is (cache_peer forcedomain=X option). But if you do so you have to
ensure that nothing, anywhere, ever references that 'private' domain in
anything produced by the virtual host. That means everything from HTTP
headers, down to embeded object links in PDFs / images / etc , and links
generated by scripts from string bits.
 It is rather a PITA to be sure you got everything if the site was not
designed to be that way from the very beginning.

> 
> What I can do is to add a cdn.example.com server alias to the origin, then
> it works of course.

Or you could use storage.example.com as the public domain name, with DNS
records pointing at the proxy IPs and let them handle the traffic
delivery like they are designed to.
 If this is a vhost on the server, then it already has a different
private name you can put in the cache_peer to get to it.

Amos



More information about the squid-users mailing list