0

Context : I'm building a cartographic service that should frequently receive weather forecasts data, process them (extract datas, create layers with associated symbology) then save them as independent projects. Then, each project can be broadcast through a WMS / WMTS, using a QGIS server.

With a contenerized approach, I have three docker containers :

  • A reverse proxy (Nginx)
  • A standalone app using qgis to process the data and creating projects
  • A qgis-server serving these projects, using a volume configuration

As I wanted to stick as much as possible to the official documentation, most of my qgis-server and nginx configuration is taken from this page : Containerized deployment

Following these steps and deploying everything with docker-compose works like a charm.

However, trying to deviate from it in order to serve multiple projects with a single qgis-server instance is harder than I expected.

I saw a few existing subjects such as QGIS Server - Docker - Multiple Projects and explored some github repos to get inspiration :

But so far I couldn't find any successful workaround.

├── nginx
│   ├── nginx.conf
│
├── qgis-projects
│   ├── osm
│   |   ├── osm.qgs
│   |   |
│   ├── osm_bis
│       ├── osm_bis.qgs
│
├── qgis-server
│   ├── cmd.sh
│   ├── Dockerfile
│
├── .env
├── docker-compose.yml
  

Dockerfile (identic to the doc version)

# Configuration taken from https://docs.qgis.org/3.28/en/docs/server_manual/containerized_deployment.html

FROM debian:bullseye-slim

ENV LANG=en_EN.UTF-8

RUN apt-get update \
  && apt-get install --no-install-recommends --no-install-suggests --allow-unauthenticated -y \
  gnupg \
  ca-certificates \
  wget \
  locales \
  && localedef -i en_US -f UTF-8 en_US.UTF-8 \
  # Add the current key for package downloading
  # Please refer to QGIS install documentation (https://www.qgis.org/fr/site/forusers/alldownloads.html#debian-ubuntu)
  && mkdir -m755 -p /etc/apt/keyrings \
  && wget -O /etc/apt/keyrings/qgis-archive-keyring.gpg https://download.qgis.org/downloads/qgis-archive-keyring.gpg \
  # Add repository for latest version of qgis-server
  # Please refer to QGIS repositories documentation if you want other version (https://qgis.org/en/site/forusers/alldownloads.html#repositories)
  && echo "deb [signed-by=/etc/apt/keyrings/qgis-archive-keyring.gpg] https://qgis.org/debian bullseye main" | tee /etc/apt/sources.list.d/qgis.list \
  && apt-get update \
  && apt-get install --no-install-recommends --no-install-suggests --allow-unauthenticated -y \
  qgis-server \
  spawn-fcgi \
  xauth \
  xvfb \
  && apt-get remove --purge -y \
  gnupg \
  wget \
  && rm -rf /var/lib/apt/lists/*

RUN useradd -m qgis

ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

ENV QGIS_PREFIX_PATH /usr
ENV QGIS_SERVER_LOG_STDERR 1
ENV QGIS_SERVER_LOG_LEVEL 2

COPY cmd.sh /home/qgis/cmd.sh
RUN chmod -R 777 /home/qgis/cmd.sh
RUN chown qgis:qgis /home/qgis/cmd.sh

USER qgis
WORKDIR /home/qgis

ENTRYPOINT ["/tini", "--"]

CMD ["/home/qgis/cmd.sh"]

cmd.sh (identic to the doc)

[[ $DEBUG == "1" ]] && env

exec /usr/bin/xvfb-run --auto-servernum --server-num=1 /usr/bin/spawn-fcgi -p 5555 -n -d /home/qgis -- /usr/lib/cgi-bin/qgis_mapserv.fcgi

docker-compose.yml, working for a single project, without tries I made to include multiple projects.

version: '3.7'

services:
  qgis-server:
    # Should use version with utf-8 locale support:
    image: qgis-server:latest
    env_file:
      - .env
    environment:
    - LANG=en_EN.UTF-8
    - QGIS_PROJECT_FILE=/data/${PROJECT_NAME}
    - QGIS_SERVER_LOG_LEVEL=0  # INFO (log all requests)
    - DEBUG=1                  # display env before spawning QGIS Server
    volumes:
    - ${PREFIX_PATH}/qgis-projects:/data:ro

  nginx:
    image: nginx:1.13
    ports:
    - 8080:80
    depends_on:
    - qgis-server
    volumes:
    - ${PREFIX_PATH}/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro

Environnent : Ubuntu throught WSL2

1 Answer 1

0

I found a workaround that seems to do the trick.

I only deleted one line inside docker-compose.yml :

version: '3.7'

services:
  qgis-server:
    # Should use version with utf-8 locale support:
    image: qgis-server:latest
    env_file:
      - .env
    environment:
    - LANG=en_EN.UTF-8
    #- QGIS_PROJECT_FILE=/data/${PROJECT_NAME} <- Delete this line 
    - QGIS_SERVER_LOG_LEVEL=0  # INFO (log all requests)
    - DEBUG=1                  # display env before spawning QGIS Server
    volumes:
    - ${PREFIX_PATH}/qgis-projects:/data:ro

  nginx:
    image: nginx:1.13
    ports:
    - 8080:80
    depends_on:
    - qgis-server
    volumes:
    - ${PREFIX_PATH}/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro

I can now reach localy these two projects : http://localhost:8080/qgis-server/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities&MAP=/data/osm_bis/osm_bis.qgs
http://localhost:8080/qgis-server/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities&MAP=/data/weather/my_project.qgs

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.