I have a setup where I have Varnish listening on Port 80 behind Apache on Port 8080 while I intend having Nginx on 8081. My vps' control panel supports only Apache but I want to test one of the sites I have hosted on my VPS on Nginx, and since Varnish is already on 80, I can't have Nginx on the same port.

I don't want to get rid of Apache completely cause I still need it to access my vps' control panel, Sentora to be precise where Apache sits on 8080. In the question asked here, the OP wanted to have two different domains on different IP's on just Apache, so it doesn't really help.

Also, I read up somewhere about using the server.port directive in my vcl but I'm not sure how to go about it. Here's what a part of my default.vcl looks like:

backend default {
    .host = "";
    .port = "8080";

P.S: I haven't installed Nginx yet.


Here you want to set up an additional backend in Varnish, and route some requests to it.

First add a new backend for Nginx:

backend nginx {
    .host = "";
    .port = "8081";

Then you can route some requests to it. This is typically done in the vcl_recv subroutine. For example, if Sentora is accessed through the domain sentora.example.org:

sub vcl_recv {
    if (req.http.host ~ "(?i)^sentora.example.org$") {
        # Route requests to sentora.example.org to the old Apache backend.
        set req.backend = default;
    } else {
        # Everything else to nginx.
        set req.backend = nginx;

See Advanced Backend configuration for more examples. There are also a lot of examples in the Varnish Configuration Language documentation.

  • hmm, awesome, what if Sentora is accessed from the vps's dedicated ip address on a specific port 8080? – Feyisayo Sonubi Jun 14 '15 at 0:45
  • @Feyisayo: I'm not sure I follow -- if Sentora is accessed on a dedicated IP and specific port, I assume it isn't accessed through Varnish? In that case, you would not need to route any requests in Varnish to Sentora, and can drop that route. – olav Jun 14 '15 at 0:58
  • Yeah, its accessed through varnish on the same Apache 8080 port. Something like http://serverip:8080 – Feyisayo Sonubi Jun 14 '15 at 1:13
  • But you said Varnish is running on port 80, while Apache is running on port 8080? If you access Sentora through http://serverip:8080/, you are accessing Apache directly, bypassing Varnish. – olav Jun 14 '15 at 1:16
  • Wow, thanks for clarifying, so if I access Sentora directly without the port number, it goes through Varnish? Also what happens if I change this port number for Sentora, it still doesn't go through Varnish right? – Feyisayo Sonubi Jun 14 '15 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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