We've been trying to get our Magento platform to work FULL with HTTPS, however, varnish doesn't work with HTTPS and then the site gets really slow... normally a page loads in 1s to 3s with https is taking about 13s.

We tried to use Nginx for HTTPS and Varnish for http, following the instructions on this link: https://www.smashingmagazine.com/2015/09/https-everywhere-with-nginx-varnish-apache/

But the site doesn't load properly, the links (js, css...) in Magento tries to load in HTTP or the site gets into a loop forever.

Any ideas or suggestions would be very appreciated.



Configure your port bindings:

  • *:8080 apache (not public accessible)
  • *:80 varnish (public accessible)
  • *:443 nginx (public accessible)

Traffic on port 80 enters Varnish which redirects to Apache backend

SSL traffic on port 443 offloads to port 80 so that Varnish handles the request.

Assuming you already have varnish and nginx installed, the following should get you going (Ubuntu/Debian OS):

Edit your nginx virtualhost configuration:

sudo vi /etc/nginx/sites-enabled/default

Configure as follows:

server {
    listen 443 ssl;

    server_name example.com;
    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header Host $host;

Replace the *.crt and *.key paths with the correct paths pointing to your ssl certificate and key.

This should set up nginx as an SSL offloader which proxies to Varnish.

Now for the actual varnish configuration file.

  1. In Magento navigate to Stores -> Configuration. Open the Advanced tab and click on the System link.

  2. Expand the Full Page Cache accordion menu and select Varnish Caching in the dropdown next to Caching application. This will enable the 'Varnish Configuration' section.

  3. The settings should be correct by default. If not, select localhost for both Access list and Backend host. The Backend Port should be set to 8080.

  4. Click on the export button corresponding to your varnish version. Magento can generate VCL files for both Varnish 3 and Varnish 4.

  5. Find your current varnish VCL file (e.g. /etc/varnish/default.vcl WHICH IS NOT THE SAME AS /etc/default/varnish) AND MAKE A COPY

  6. Replace the varnish VCL file with the file you got from Magento.

  7. Restart everything.


  • Good answer. How to do this with Apache only (where Apache serves public port 443 as well as internal port 8080)?
    – MountainX
    Dec 2 '19 at 1:03

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.