Skip to content

Instantly share code, notes, and snippets.

@klaasvw
Created October 10, 2012 06:41
Show Gist options
  • Save klaasvw/3863541 to your computer and use it in GitHub Desktop.
Save klaasvw/3863541 to your computer and use it in GitHub Desktop.
Set up Varnish to proxy to a different host
# Add this code to your VCL configuration.
#
# I assume a default backend has already been configured.
# If different from the default backend, add one for the host to proxy to. Note that these
# values are just examples.
backend proxy_host {
.host = "proxy_host.dev";
.port = "8080";
}
# This is where the magic happens. We detect an incoming request and proxy it to the other
# host.
# Note that is a very bare bones setup, purely for illustrating you to proxy.
sub vcl_recv {
if (req.http.host ~ "^incoming_host\.dev") {
set req.http.X-Forwarded-Host = req.http.host;
set req.http.host = "proxy_host.dev";
set req.backend = proxy_host;
}
return (pass);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment