Docker4drupal: When using varnish

Created on 11 May 2017  路  5Comments  路  Source: wodby/docker4drupal

I have attempted to setup the varnish container but when I check to see if it is caching anything I do not see the headers X-Varnish-Cache. Varnish starts. Try viewing varnish logs and really nothing is going on. Nginx is doing a lot. Drupal says varnish is running. I think it has to do with maybe some port config? Not sure.

Any ideas would be helpful!

Thank you!

Most helpful comment

Ok I think I figured it out.. I just had to change the Traefik frontend rule for nginx to point at nginx.drupal.docker.localhost and varnish to drupal.docker.localhost. I kept messing with ports as well which I guess traefik doesn't really care about.

All 5 comments

After looking into this more. While varnish starts up fine on port 6081-6082. Drupal says it is running because it checks 6082. However, no traffic is hitting the cache because I am pointing my traffic towards 80 which is nginx so it bypasses varnish entirely.

Based on the wodby compose setup I am uncertain I can get the ports configured correctly from configuration to go through varnish and then end up going through nginx to hit the frontend.

Please advise. I am pretty sure I can get this to run with a modified varnish/nginx config so I will try that and post my findings.

-Jesse

Follow up to this. I also was unable to find a /etc/default/varnish config file on the container so I am guessing I could mount this as a volume and get closer.

Varnish is already configured to use nginx as its backend. You can see in the compose file that varnish is accessible as varnish.drupal.docker.localhost via traefik. Our varnish caching tests pass, so most likely you're doing something wrong. See https://github.com/wodby/drupal-varnish for more details.

P.S. I didn't even tell what is your Drupal version

I am using Drupal 7. Agree, Varnish is already configured to use nginx as it's backend. This is true, but how do you use varnish as the frontend (so to speak). It seems that traefik just goes straight to nginx through port 80. So nothing hits varnish.

It should go (from my understanding) port 80/443 (traefik) > 6081 (varnish) deliver cache OR continue > 80 (nginx). I am unable to figure out how to have it hit 6081 first though. None of the docs show. Just having varnish.drupal.docker.localhost accessible doesn't mean traffic is going through it.

I am not sure I want varnish used on every site (it's a multisite setup) so setting ports in traefik to map 80 to 6081 doesn't seem like the best solution. I would imagine the best way for this would be to have varnish listen on port 80 and nginx on say 8000 and have it go that way but it seems that the varnish and nginx docker containers are not setup to accept this configuration. I would have to modify.

Regardless still find it hard to understand that varnish is working in your tests. Because I don't even get a X-Varnish-Hit or Miss header.

I appreciate your looking into his for me.

Going directly to varnish.drupal.docker.localhost does report varnish headers and loads sites fine. So I guess I just need to figure out how to route traffic through varnish instead of bypassing it.

Ok I think I figured it out.. I just had to change the Traefik frontend rule for nginx to point at nginx.drupal.docker.localhost and varnish to drupal.docker.localhost. I kept messing with ports as well which I guess traefik doesn't really care about.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dcre picture dcre  路  6Comments

featherbelly picture featherbelly  路  5Comments

LordFransie picture LordFransie  路  3Comments

quietone1 picture quietone1  路  10Comments

2dareis2do picture 2dareis2do  路  11Comments