How to configure varnish cache for a domain in Plesk?

Follow

Comments

17 comments

  • Avatar
    Guido Wiedner

    Are the instructions still up to date?
    I tried to install varnish 7.1.2.
    docker status shows the message: is assigned with an IP address 172.17.0.0/16
    I've changed that accordingly. But the container does not start.
    Error: Could not get socket :80: Permission denied (-? gives usage).
    I can't find any /etc/varnish/default.vcl either
    -bash: cd: /etc/varnish: No such file or directory
    Under the domain in Add Docker Proxy Rules, there is also no entry under Port
    I appreciate any help.
    Thanks very much

    0
    Comment actions Permalink
  • Avatar
    Stefan Yakubov

    Yes, please follow the instructions using the stable docker version specified in there.

    0
    Comment actions Permalink
  • Avatar
    Stefan Braunersreuther (Edited )

    Until yesterday we had a great running Varnish Cache in Docker, thanks for the great tutorial. Tonight an update made our Varnish cache unusable. The beautiful error message 503 appears.
    The following packages were successfully updated:
    - containerd.io 1.6.24-3.1.el8 from the plesk-ext-docker repository (previous version: 1.6.22-3.1.el8 from the plesk-ext-docker repository).

    Update: After a second server restart and a reinstallation of Varnish, the error was gone.

    Greetings
    Stefan

    0
    Comment actions Permalink
  • Avatar
    Stefan Yakubov

    Hello, Stefan Braunersreuther

    By the looks of it, the application itself was rather down or misconfigured within the container. Next time this happens, you can enter the container via docker CLI and have a look at the varnish status.

    E.g., is it running/listening on the ports.

    0
    Comment actions Permalink
  • Avatar
    Bragi Austson

    Varnish Cache works really well for wordpress but for other CMS systems like Joomla 5 - 4 is not working at all.

    In CWP the Varnish Cache works like a charm

    0
    Comment actions Permalink
  • Avatar
    Stefan Yakubov

    Hi, Bragi.

    Yes that is expected, Joomla will require a different varnish configuration. For instance, you can review the following gists and adjust one for your needs:

    https://gist.github.com/fevangelou/84d2ce05896cab5f730a

    0
    Comment actions Permalink
  • Avatar
    Kev Quirk

    This seems to be working well for me, but I have a control panel on my site at /panel. Normally I would just add the following to my default.vcf:

    sub vcl_recv {
        if (req.url ~ "^/panel($|/.*)") {
            return (pass);
        }
    }

    But I can't find a way to that with Docker on Plesk. How would I do it?

    0
    Comment actions Permalink
  • Avatar
    Christos Tziotzis

    Do we need to have multiple varnish containers for each domain we decide to proxy through varnish?

    I'm concerned about the memory usage

    0
    Comment actions Permalink
  • Avatar
    Stefan Yakubov

    Hello, Christos Tziotzis

    One container per IP Address. The number of domains doesn't matter as long as they use the IP Address specified in the varnish conf file inside of a container

    0
    Comment actions Permalink
  • Avatar
    Carrero

    this .sh run with almalinux or rockylinux ??

    0
    Comment actions Permalink
  • Avatar
    Stefan Yakubov

    Hello, Carrero

    I've tested this on AL8/9 and RockyLinux 8

    Works in a clean Plesk installation with default OS repos.

    0
    Comment actions Permalink
  • Avatar
    Bragi Austson (Edited )

    I followed this "Via the custom varnish management script for Plesk" Varnish Cache is running fine, if I use more that 1 WordPress install everything stops working. Varnish Cache will work for some hours then everything will stop working.

    I have 18 domains and I want to use Varnish Cache for them all. I´m not a hosting company, I host my own stuff for my own purpose.

    I will try using docker and let you all know how that goes.

    Edit:

    I have a question! I have 2 wordpress and both are using docker Varnish Cache.

    What plugin can I use for Wordpress that will flush varnish cache, I have used WP Total Cache and proxy cache purge, it seems that neither plugins are able to flush the cache, the only way for me to flush the cache is restarting the docker.

    I have tried to add my public IP, my local IP and even used 172.17.0.0 it doesn´t matter what I try nothing works.

    Also there is missing how to uninstall varnish cache for "varnishmng.sh"

    0
    Comment actions Permalink
  • Avatar
    Yiorgos Zachariades

    Bragi,

    I am using Proxy cache purge and have to change the IP Address of the Varnish to be 127.0.0.1:32780. And I also had to edit default.vcl and add "172.17.0.1" to the allowlist for Purges in Varnish. Then the purging from Varnish works as expected.

    0
    Comment actions Permalink
  • Avatar
    Yiorgos Zachariades

    Plesk Team,

    Thank you for this guide as this works pretty well and it actually helps with performance a lot.

    The only thing that I can think that needs adjustment is the httpd.conf and/or nginx.conf to allow us to still be able to view the /plesk-stat/ URLs for the domains that we setup in Varnish/Docker. 

    After following the guide you have here, trying to access the /plesk-stat/webstat-ssl/ or /plesk-stat/webstat/ gives out infinite 301 redirects. This is due to the fact that the Apache 7080 internal port is redirecting to the https://....../plesk-stat/ which then gets routed by the Docker proxy back to the 7080, and so on, causing an infinite loop.

    I was able to resolve this by commenting out the https:// redirects in the virtualhost part for port 7080 and adding the basic authentication/location parts for the /plesk-stat/ that exist on port 7081, to port 7080 and the /plesk-stat/ works together with Varnish and Wordpress.

     

    But unfortunately any change I make the domain through the Plesk GUI is going to reset my http.conf and /plesk-stat/ will stop working again. I would do this through the custom template folder but I do not want to make all my domains pass through Varnish yet, as I'm still testing each domain one by one before enabling Varnish on it.

    Any chance you can account for this in a future update? 

    0
    Comment actions Permalink
  • Avatar
    Stefan Yakubov

    Hello, Yiorgos Zachariades.

    Are you using the dockerized version, or in-place varnish installation with a script?

    0
    Comment actions Permalink
  • Avatar
    Yiorgos Zachariades

    Hello Stefan,

     

    I am using the Dockerized version of Varnish.

    0
    Comment actions Permalink
  • Avatar
    Jason Winley

    Varnish works great thanks! Unfortunately any password protected pages via Wordpress will not be honoured (say if set to private with a password) or using .htaccess passwords do not work. Is there any fix for this?

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request