-1

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

1 Answer 1

1

As far as 503 errors go, you can use varnishlog to debug. Please run the following command in your Varnish container to figure out what's going on:

docker exec -ti -u0 cache varnishlog -g request -q "RespStatus == 503"

Please attach the relevant log output to your question.

However, your docker-compose.yml seems to expose some inconsistencies: your tiles server does a 32772:7800 portforwarding. Meaning local port 32772 is being forwarded to host port 7800.

The BACKENDS environment variable of your cache container still refers to local port 7800 on the tiles container.

Either your change the local port of your tiles server back to 7800 as done in the tutorial. Or if for some reason, port 32772 is the right one, alter your BACKENDS configuration and point it to port 32772.

Please also consider using the official Varnish Docker image. It is supported by the community and by Varnish software.

Sign up to request clarification or add additional context in comments.

1 Comment

I edited the compose file, the port forwarding for the tiles is not needed as I am exposing through nginx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.