1

I am trying to configure Varnish cache on Magento 2.3 with SSL termination, but no luck so far.

Here is my configuration:

/etc/apache2/ports.conf

Listen 8080

<IfModule ssl_module>
        Listen 443
</IfModule>

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

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

<VirtualHost *:8080>

/etc/apache2/sites-available/magento2.conf

<VirtualHost *:8080>
     ServerAdmin contact@website.com
     DocumentRoot /var/www/html/magento2/
     ServerName website.com
     ServerAlias www.website.com

     <Directory /var/www/html/magento2/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

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

<VirtualHost *:443>
        ServerName website.com
        ServerAlias www.website.com
        DocumentRoot /var/www/html/magento2/

        ProxyPreserveHost on
        ProxyPass / http://127.0.0.1:8080/
        RequestHeader set X-Forwarded-Port "443"
        RequestHeader set X-Forwarded-Proto "https"

        SSLEngine On
        SSLCertificateFile /etc/ssl/certs/website.com.crt
        SSLCertificateKeyFile /etc/ssl/private/website.com.key
        SSLCertificateChainFile /etc/ssl/website.com.ca-bundle
        <Directory /var/www/html/magento2/>
                Options Indexes FollowSymLinks MultiViews
                Order allow,deny
                AllowOverride All
        </Directory>
</VirtualHost>

/etc/varnish/default.vcl

backend default {
    .host = "52.56.108.15";
    .port = "8080";
    .first_byte_timeout = 600s;
    .between_bytes_timeout = 600s;
    .probe = {
        .url = "pub/health_check.php";
        .timeout = 2s;
        .interval = 5s;
        .window = 10;
        .threshold = 5;
   }
}

/etc/default/varnish

DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
     -f ${VARNISH_VCL_CONF} \
     -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
     -p thread_pool_min=${VARNISH_MIN_THREADS} \
     -p thread_pool_max=${VARNISH_MAX_THREADS} \
     -p http_resp_hdr_len=65536 \
     -p http_resp_size=98304 \
 -p workspace_backend=98304 \
     -S ${VARNISH_SECRET_FILE} \
     -s ${VARNISH_STORAGE}"

Magento Cache config:

Access list: 127.0.0.1
Backend host: 52.56.108.15
Backend port: 8080
Grace period: 300

Here is how my response headers look at this point:

Cache-Control: max-age=0, must-revalidate, no-cache, no-store
Connection: Keep-Alive
Content-Encoding: gzip
Content-Security-Policy: upgrade-insecure-requests
Content-Type: text/html; charset=UTF-8
Date: Fri, 22 Mar 2019 18:00:29 GMT
Expires: Thu, 22 Mar 2018 18:00:29 GMT
Keep-Alive: timeout=5, max=100
Pragma: no-cache
Server: Apache/2.4.29 (Ubuntu)
Set-Cookie: PHPSESSID=fh1hcnrcvs4u25lp1kqq7sv8br; expires=Fri, 22-Mar-2019 19:00:29 GMT; Max-Age=3600; path=/; domain=website.com; HttpOnly
Set-Cookie: form_key=Hu9gu1oJeyjVzCjm; expires=Fri, 22-Mar-2019 19:00:29 GMT; Max-Age=3600; path=/; domain=website.com
Strict-Transport-Security: max-age=31536000
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-UA-Compatible: IE=edge
X-XSS-Protection: 1; mode=block

Can anyone help with this issue? Thanks in advance!

Your Answer

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

Browse other questions tagged or ask your own question.