I am following the tutorial production-postgis-vector-tiles-caching. However when I try to setup pg_tileserve to serve tiles under reverse proxy and varnish also under reverse proxy, I always get an error Error 503 Backend fetch failed. My docker-compose looks like
tiles:
image: pramsey/pg_tileserv
volumes:
- ./config/pg_tileserv.toml:/etc/pg_tileserv.toml
environment:
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASS}@${POSTGRES_HOST}/${POSTGRES_DB}
- TS_URLBASE=${VECTOR_TILES_URL}
- TS_BASEPATH=/tiles
depends_on:
db:
condition: service_healthy
restart: always
cache:
image: eeacms/varnish
environment:
BACKENDS: 'tiles:7800'
DNS_ENABLED: 'false'
COOKIES: 'true'
PARAM_VALUE: '-p default_ttl=600'
VARNISH_BACKEND_PATH: '/'
depends_on:
tiles:
condition: service_started
restart: always
nginx:
image: nginx
volumes:
- ./sites-enabled:/etc/nginx/conf.d:ro
depends_on:
- tiles
- cache
ports:
- "80:80"
And my nginx config looks like this:
location /tiles {
proxy_pass http://tiles;
}
location /cache {
proxy_pass http://cache;
}
How can I modify my varnish config, considering my tiles are available on http://localhost/tiles and varnish should be available from http://localhost/cache
As far as 503 errors go, you can use
varnishlogto debug. Please run the following command in your Varnish container to figure out what's going on:Please attach the relevant log output to your question.
However, your
docker-compose.ymlseems to expose some inconsistencies: yourtilesserver does a32772:7800portforwarding. Meaning local port32772is being forwarded to host port7800.The
BACKENDSenvironment variable of yourcachecontainer still refers to local port7800on thetilescontainer.Either your change the local port of your
tilesserver back to7800as done in the tutorial. Or if for some reason, port32772is the right one, alter yourBACKENDSconfiguration and point it to port32772.Please also consider using the official Varnish Docker image. It is supported by the community and by Varnish software.