title: Varnish Vcl for multiple incoming and outgoing port connections
body: <p>Since a little while I am using Varnish Cache solutions and as long as the configuration was more or less the same as it was after the installation everything worked out very well.</p>
  
  <p>But now I like to do a little bit more with Varnish. Currently I am using the following setup for my servers :</p>
  
  <p>Visitors -> CloudFlare -> HaProxy -> Varnish (separate servers) -> Apache2 Content.</p>
  
  <p>What I like to know is how am I able to make the right vcl script to accept let's say an incoming request from ip A on port B and redirect this to ip C on port D. (And this more than once.)</p>
  
  <p>Example :</p>
  
  <p>Default.Varnish works well like this:</p>
  
  <pre><code>DAEMON_OPTS="-a :8085,:8087 \
               -T localhost:6082 \
               -f /etc/varnish/default.vcl \
               -S /etc/varnish/secret \
               -s malloc,768m"
  </code></pre>
  
  <p>But now about the Varnish.Default :</p>
  
  <pre><code>backend default_1 { .host = "11.22.333.444"; .port = "8885"; }
  backend default_2 { .host = "11.22.333.444"; .port = "8887"; }
  </code></pre>
  
  <p>And I tried something like this :</p>
  
  <pre><code>sub vcl_recv {
   if (server.port == 8885) { set req.backend = default_1; }
   if (server.port == 8887) { set req.backend = default_2; }
  }
  </code></pre>
  
  <p>(Please be aware of the fact that both requests are going to the
  same outgoing server. Only the port is different!)</p>
  
  <p>Someone who knows enough from Varnish already knows what I want I guess. I just like to use Varnish to proxy separate 'channels' based on different ports.</p>