Centos – httpd vhosts config (with Varnish) – 1 server /w multiple domains

centoshttpdvarnishvirtualhost

I've been reading multiple questions about this topic but I can't seem to get it working…

I have a server running CentOS with HTTPD running 1 website under the default httpd root:

Listen 8080
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>`

I'm also running Varnish: Varnish is listening on port 80 and forwarding requests to httpd, which is listening on port 8080

Now I want to run a second domain on this server, so I added a .conf file under /etc/httpd/conf/ with the following:

<VirtualHost *:8080>
ServerAdmin root@localhost
DocumentRoot /var/www/vhosts/domainx.be
ServerName domainx.be
ErrorLog logs/domainx-error_log
CustomLog logs/domainx-access_log common
</VirtualHost>

When I apply the above, all traffic (including that of the root domain) is routed to domainx. When I change the port of the vhost to 80, domainx gets forwarded to the root host.

This is the first time I'm doing this without something like Plesk of Webmin installed so I'm not sure where to go from here….

Best Answer

  • Create a virtual host for your website which is pointing to the document root. Remember adding NameVirtualHost *:8080.

  • Put the backend configuration in one file and then include it based on the hostname requested:

       if (req.http.Host == "domainx.be") {
           include "/etc/varnish/domainx.be.vcl";
       }
    
Related Topic