Ubuntu 14.04 Apache + SSL server, how to configure Varnish

Ubuntu 14.04 Apache + SSL server, how to configure Varnish

October 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Ubuntu 14.04 Apache + SSL server, how to configure Varnish

Setting Up Varnish with SSL on Ubuntu 14.04 Apache Server

As a seasoned Magento developer and technical blogger at Laravel Company, I frequently encounter challenges like this from my clients and fellow developers. Configuring Varnish for improved caching performance while maintaining secure SSL connections can be complex, especially without the use of Nginx.

Understanding the Current Setup

Your current setup appears to be a standard Apache2 virtual host configuration with SSL enabled. The SSLEngine is set to “on”, and you’ve defined the paths to your SSL certificate, private key, and CA bundle correctly within the <VirtualHost *:443> block.

The redirection from HTTP port 80 to HTTPS port 443 is handled in the second <VirtualHost *:80> block using a RewriteRule. This ensures that all non-SSL requests are permanently redirected to the SSL version of your site.

Configuring Varnish for SSL

To set up Varnish with SSL, you’ll need to use a reverse proxy configuration. Varnish itself doesn’t handle SSL/TLS termination; it requires an underlying server like Apache or Nginx to manage this layer.

First, let’s create a new file /etc/apache2/sites-available/varnish.conf and add the following content:

<VirtualHost *:80>
    ServerName mysite.com
    ServerAlias www.mysite.com

    RewriteEngine On
    RewriteRule (.*) http://127.0.0.1:6081$REQUEST_URI [P,L]
</VirtualHost>

Here, we’re creating a new virtual host that listens on port 80 and rewrites all incoming requests to Varnish running on localhost on port 6081.

Configuring Varnish

In your main vcl file (usually located at /etc/varnish/vcl.default.vcl), you need to ensure the backend definition points to Apache. Modify or add a new backend block:

backend default {
    .host = "localhost";
    .port = "443";
}

Conclusion

With this setup, Varnish will handle all incoming requests and provide cached responses where possible. For uncached content, it will forward the request to your Apache server running on port 443.

Remember to restart Varnish (and possibly Apache) after making these changes using the commands:

sudo service varnish restart
sudo systemctl restart apache2

This configuration ensures that you maintain secure SSL connections while leveraging Varnish for improved performance. For more in-depth guides and best practices on Magento performance optimization, feel free to explore our resources at Laravel Company.

Cache Performance Configuration CLI

Our network