2

I’m trying to set up Varnish and Apache to serve multiple websites from one VPS. However, when I enter seconddomain.nl in a browser, I am redirected to the default apache2 start page (with a url that is the VPS IP address). However, firstdomain.nl works just fine. My setup is this:

etc/default/varnish:

DAEMON_OPTS="-a :80 \
             -T localhost:1234 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

(some parts omitted)

/etc/varnish/default.vcl:

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

/etc/apache2/ports.conf:

NameVirtualHost *:8080
Listen 127.0.0.1:8080

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

/etc/apache2/sites-available/000-default.conf:

<VirtualHost *:8080>
        ServerName 188.166.71.35

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

         <Directory /var/www/jws/>
            AllowOverride All
         </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/etc/apache2/sites-available/seconddomain.nl.conf:

<VirtualHost *:8080>

        ServerAdmin janwillem@seconddomain.nl
        ServerName seconddomain.nl
        ServerAlias www.seconddomain.nl
        DocumentRoot /var/www/jws

        php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -fjanwillem@seconddomain.nl
        ErrorLog ${APACHE_LOG_DIR}/error-seconddomain.log
        CustomLog ${APACHE_LOG_DIR}/access-seconddomain.log combined
</VirtualHost>

/etc/apache2/sites-available/firstdomain.nl.conf:

<VirtualHost *:8080>

        ServerAdmin info@firstdomain.nl
        ServerName firstdomain.nl
        ServerAlias www.firstdomain.nl
        DocumentRoot /var/www/firstdomain.nl

        php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -finfo@cool-hou$
        ErrorLog ${APACHE_LOG_DIR}/error-firstdomain.log
        CustomLog ${APACHE_LOG_DIR}/access-firstdomain.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =firstdomain.nl [OR]
RewriteCond %{SERVER_NAME} =www.firstdomain.nl
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
Flobin
  • 626
  • 1
  • 10
  • 26
  • 1
    Does it work without Varnish? (If you surf to :8080 with both domainnames?) – Jensd May 06 '16 at 14:42
  • @Jensd with curl and in the browser on my local machine I get: Failed to connect to seconddomain.nl port 8080: Operation timed out. Same for the first domain. In the VPS I get connection refused (for both). – Flobin May 06 '16 at 19:56
  • Then your problem is with Apache or the server itself - not Varnish! Any firewall running? – Jensd May 07 '16 at 08:33
  • @Jensd so with `netstat -ln | grep 8080` I get `tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN`, which would indicate that apache is listening to port 8080 locally. (It's on the same VPS as varnish.) – Flobin May 07 '16 at 09:14
  • Try setting the actual IP instead of 127.0.0.1 or localhost – Jensd May 07 '16 at 10:57
  • @Jensd I tried that, but I got `Error 503 Backend fetch failed` from Varnish. – Flobin May 09 '16 at 12:51
  • I meant both in Apache and Varnish! Also I wonder if you really need /etc/apache2/sites-available/000-default.conf? Anyway - you need to get it working without Varnish first! – Jensd May 09 '16 at 13:29

1 Answers1

0

I had the same configuration as yours, and what solved it was to remove the 127.0.0.1 in /etc/apache2/ports.conf

This is how I have now and it works (I commented the changed line):

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

#Listen 127.0.0.1:8080
Listen 8080

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>