1

I want to install and configure varnish with Magento 2 on my server running apache as incredibly impressed with the performance gains. Just wanted to know a bit about configuring SSL with this as have not done this in my dev environment.

I have also however been told by my hosting provider that to have varnish work on my site i can only have one site on my server. Is this correct? My testing shows multiple sites seemingly working fine so wondering what this could be about?

2

Varnish in the open source version does not support SSL termination. Therefore you have to set up a reverse proxy like a nginx or similar. The nginx is responsible to terminate the SSL and forward the request to varnish.

Magento 2 works well with varnish, even in a multi-site environment.

As you use Apache, you need to enable mod_proxy. In addition to that add a virtual host that listens to port 443 like so:

#/etc/apache2/sites-available/your-site.com-ssl
<VirtualHost *:443>
    ServerName www.your-site.com

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

    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/example.com.crt
    SSLCertificateKeyFile /etc/apache2/ssl/example.com.key
    SSLCertificateChainFile /etc/apache2/ssl/example.com.chain
</VirtualHost>

The ProxyPass should point to your varnish instance.

  • I may swap over to NGINX but am using Apache at the moment and want some advice on SSL termination with Apache really, any thoughts?. – harri Nov 21 '17 at 11:06
  • see answer update – David Lambauer Nov 21 '17 at 12:31
  • Brilliant i shall give this a go and have a little test. – harri Nov 21 '17 at 12:46
  • I did seem to get that working but speeds do seem to drop for request by like 1ms to 500ms. Anything to do for this? – harri Nov 21 '17 at 17:02
  • Sorry, I only know some basics of Apache. I never encountered those issues with nginx. You might give it a shot. – David Lambauer Nov 21 '17 at 17:05
1

Don't worry about your hosting's comment. Varnish is transparent HTTP caching proxy, it doesn't care how many website go through it. One or one hundred will work equally fine.

Worry about your hosting support being incompetent.. :)

0

Please check here how to setup varnish cache in magento2

https://www.cloudways.com/blog/magento-2-varnish-setup/ http://devdocs.magento.com/guides/v2.0/config-guide/varnish/config-varnish.html

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.