qgis / qgis-docker

Official Docker image for QGIS Server and Desktop
GNU Affero General Public License v3.0
67 stars 21 forks source link

How to get correct rewrite URLs when using NGINX reverse proxy inside the container? #84

Open jacobwod opened 9 months ago

jacobwod commented 9 months ago

Problem description

I can't figure out how the URLs inside the responses (e.g. WFS3 JSON response or the WMS GetCapabilities) get their hostname.

I have a scenario where the container runs with its built in NGINX. In addition, I have another application in front of the QGIS Server, which has its own proxy mechanism through with I expose the container. So to get a response from e.g. the WFS3 endpoint, I can reach it at:

https://hajkmap.example.com/api/v1/proxy/qgisserver/wfs3/wfs.json?MAP=/io/data/testproj/testproj.qgs

But the response contains references to container's internal endpoint:

Skärmavbild 2023-09-25 kl  13 32 24

Furthermore, I have no idea where the hostname ofhttps://qgis-server:443 comes from as my docker-compose.yaml looks like this:

services:
    qgis-server:
        image: 'opengisch/qgis-server:ltr-jammy' # We want the latest LTR based on Ubuntu 22.04
        hostname: hstd_qgisserver
        container_name: qgis-server-hstd

What I try to do

I would like my responses from the OGC services (whether it's the already mentioned WFS3 or e.g. WMS with its XML responses) to contain the URL to my proxy (https://hajkmap.example.com/api/v1/proxy/qgisserver) instead of the current value (https://qgis-server:443).

NB: I can't do this using the QGIS project file's "Announced URL" function because the address of the proxy will vary, depending on the node running the container (it could be at https://production-server.example.com/api/v1/proxy/qgisserver as well as https://internal-test-server.example.com/api/v1/proxy/qgisserver).

NB 2: I could of course build unique containers on each of the nodes and in the ADD step in Dockerfile copy the modified nginx.conf. But this would, in my opinion, overcomplicate things as the only difference between the images would be that single line in nginx.conf.

Ideally I need to specify a value inside the Docker Compose file (or using an environmental variable on the node running the container) and have that value passed all the way to container's /etc/nginx/nginx.conf. image

I hope to hear some ideas from you. Thank you for your hard work! 🚀

JakobMiksch commented 2 months ago

You can also try to set the HTTP header by your proxy in front of QGIS Server. But that's a different approach compared to rewrite it with NGINX / APACHE

https://docs.qgis.org/3.34/en/docs/server_manual/config.html

image