Hestia with Varnish

It’s been a couple of years since we discussed this, so I’m wondering if anyone has successfully integrated Varnish with a Hestia web template?

2 Likes

Why Varnish?

Hi @schiwe – We’ve been able to get our ttfb on a Magento server down to 300ms but we’ve been interested in adding Varnish to the server to lower our ttfb and increase our user experience.

Currently, we’re working on it with Hestia 1.5.15 and may be close to a working model.

Any input or suggestions from you or others is appreciated.

I am very interested also in getting a lower ttfb by using varnish or any other method.

1 Like

We found simply by adding Redis, which works well with Hestia’s Magento template, as well as editing some php settings worked well. However, Varnish is something we really want to use.

In our testing without the Hestia panel, our ttfb using Redis and Varnish got us between a 35-50ms ttfb on a heavily loaded page.

So now we’re working on incorporating Varnish into our Hestia machines.

Move nginx from port 80 to a different port

Edit /etc/nginx/conf.d/ip.conf

Edit /usr/local/hestia/conf/hestia.conf and modify web_port or proxy_port (And ssl ports)

Safe and rebuild webdomain configs

2 Likes

Thanks @eris we’re going to spend some more time on it, hopefully to get Varnish working alongside the Hestia Magento template. :slight_smile:

Struggling with this trying to get Nginx to stop using port 80. Modified /usr/local/hestia/conf/hestia.conf and /usr/local/hestia/conf/defaults/hestia.conf

It have Varnish running on port 80 and want to switch Nginx to port 8080 but even with restarts, every time I run Nginx, it uses the new ports plus still uses 80, so Varnish has a port conflict. Going the other way, same issue, Nginx has a port conflict.

Not sure what I’m missing to stop Nginx from using port 80.

EDIT: Okay, found what I was missing. I had to change every domain, including the server domain to stop using port 80 so Nginx wouldn’t use it. Now Nginx is using 8080 and 443, however I’m not seeing the speed increase with the Hestia/Varnish combo that I was with Varnish and no panel. Hmmm… More digging…

Been reading all morning on how to proxy-pass 443 to 80, since it seems the webserver is bypassing Varnish and using port 443 and never reaching Varnish port 80.

Is there something I need to add to the /usr/local/hestia/conf/hestia.conf to tell the server to forward 443 to 80 so Varnish works with https?

Added PROXY_SYSTEM, PROXY PORT AND PROXY SSL PORT and saw the NGINX proxy option in CONFIGURE > WEB

Still ignores 443 > 80 > 8080. Also edited the templates in hestia/nginx/templates to switch under the domain proxy setting (new window) and still ignored.

I know that servermom.org has articles about getting vesta and varnish working together, I’m quite sure of that

Thanks for the comment @aaronkempf . I was looking at this VestaCP Configuration for Varnish Cache Server as well as the last comment on this blog post last week, and still no luck getting Varnish to work with Hestia and Magento.

However, I found this Magento/Vesta/varnish template VestaCP Magento2 Varnish Template With SSL Termination · GitHub yesterday and was going to bang around with it today.

I’m sure there is something simple that I’m overlooking to get Varnish to function.

Instead of trying to replace Nginx on port 80, you should use Nginx on port 80 and 443 (especially for SSL offloading) and use a ProxyPass to send to Varnish and then back to Nginx on another port.

This is how I do it on non-Hestia servers for Magento. Nginx as, essentially, an SSL offloaded and load balancer, feeding Varnish and getting requests back to go to PHP-FPM or Apache.

2 Likes

The path I’ve been trying to use is: ( Nginx ( 80/443 ) ---> Varnish ( 6081 ) ---> Nginx (8081) ---> php-fpm.

However it’s the ProxyPass issue I’ve been having trouble with. Not sure where to instruct Hestia to use a ProxyPass to send 443 to 6081.

I’d create a new template. Copy this file and edit it, calling it varnish.stpl or similar.

/usr/local/hestia/data/templates/web/nginx/default.stpl  

Add the ports for Varnish and see what happens.

Nope, not happening. I simply can’t get Varnish working with Hestia and Magento. :frowning:

wow this is beyond me, I’m gonna bow out.

Still going for: ( Nginx ( 80/443 ) ---> Varnish ( 6081 ) ---> Nginx (8081) ---> php-fpm.

tcp        0      0 0.0.0.0:6081            0.0.0.0:*               LISTEN      5394/varnishd       
tcp        0      0 127.0.0.1:6082          0.0.0.0:*               LISTEN      5394/varnishd       
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      521/php-fpm: master 
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      581/mariadbd        
tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      1384/exim4          
tcp        0      0 192.168.1.233:80        0.0.0.0:*               LISTEN      3703/nginx: master  
tcp        0      0 192.168.1.233:8081      0.0.0.0:*               LISTEN      3703/nginx: master  
tcp        0      0 0.0.0.0:465             0.0.0.0:*               LISTEN      1384/exim4          
tcp        0      0 0.0.0.0:8083            0.0.0.0:*               LISTEN      583/nginx: master p 
tcp        0      0 127.0.0.1:8084          0.0.0.0:*               LISTEN      3703/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      582/sshd: /usr/sbin 
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      1384/exim4          
tcp        0      0 192.168.1.233:443       0.0.0.0:*               LISTEN      3703/nginx: master  
tcp        0      0 127.0.0.1:9981          0.0.0.0:*               LISTEN      522/php-fpm: master 
tcp6       0      0 :::6081                 :::*                    LISTEN      5394/varnishd       
tcp6       0      0 :::22                   :::*                    LISTEN      582/sshd: /usr/sbin 
udp        0      0 0.0.0.0:68              0.0.0.0:*                           466/dhclient 

Now stuck on:

Error 503 Backend fetch failed

Backend fetch failed

Guru Meditation:

XID: 12

Varnish cache server

There has got to be something I’m simply missing… This has become my life :slight_smile:

So I got it working, getting a 330ms ttfb with Hestia (plus Redis) down to 51ms ttfb without Hestia, but I really would prefer to keep the Hestia panel with Varnish.

Working model: After installing Nginx, PHP, Elasticsearch etc etc and have a working M2 store:

  • Edit /etc/varnish/default.vcl and copy Magento Varnish 6 config file replacing default
  • Edit /etc/systemd/system/varnish.service and create a new Varnish answer file
  • Edit /etc/nginx/sites-available/magento with Magento/Varnish template
  • Restart Nginx and Varnish and done.

So how do I alter this config to work with Hestia? If I replace the Hestia Magento template with the Vesta/Magento templates in the link VestaCP Magento2 Varnish Template With SSL Termination · GitHub do I continue to use or edit the Hestia Nginx template?

Still can’t get a staging server merging a working M2/Nginx/Varnish config with Hestia, so hoping for some guidance.

afaik varnish does not do ssl termination and that is what leads to double proxying.

if you start from “behind” you first setup your hestia with nginx+php-fpm and get your mage2 running.
in the next step you would want to install vanrish, but make sure it’s running on a different port, like the 6081 or whatever.
now you need to tell nginx (via some template for hestia) that it should proxy all 443 requests to varnish and varnish that it should proxy all request to port localhost:80

I would not change the nginx port from 80 to something else for that matter and also not proxy incoming port 80 requests to varnish. if ou really want to double up on the ports leave port 80 in nginx for redirecting to https and put a seperate block for the port you want to proxy to.

however, without seeing your config files I am afraid we can’t help much…

I am unavailable next week, but can offer to have a look at your staging server in the week after. simply because I am interested in that setup for my own use but to lazy for now to spin up a whole staging playground myself :wink: :wink: