Skip to Content
Operate

Reverse proxy

Serve GeoMetrikks over HTTPS behind nginx, SWAG or another proxy, and make the app record the real client address.

GeoMetrikks works behind a reverse proxy that terminates TLS. Give it its own subdomain, such as geometrikks.example.com. The frontend is built for the site root, so a subfolder such as example.com/geometrikks/ breaks the app: its pages and assets load from /.

This page is about the requests your browser sends to GeoMetrikks itself. To get the visitor's address into the access logs GeoMetrikks reads, see Real client IP behind a proxy.

Settings for HTTPS

APP_SESSION_SECURE=true
APP_TRUSTED_PROXIES=172.30.0.0/24

APP_SESSION_SECURE=true marks the session cookie Secure, so the browser only sends it over HTTPS. Over plain HTTP the login then stops working, so set it only once the proxy serves HTTPS. With OpenID Connect, OIDC_REDIRECT_URI is the app's public https address, and startup fails unless APP_SESSION_SECURE=true is set too. See The callback URL.

APP_TRUSTED_PROXIES lists the proxies the app takes X-Forwarded-For from. Use the narrowest range that covers your proxy. With Docker that is the subnet of the network the proxy and GeoMetrikks share; docker network inspect <name> shows it.

The client address

The app resolves the client address of every request it serves through APP_TRUSTED_PROXIES. It records that address in:

  • the login log, on login, logout and failed login lines, and on the OpenID Connect login lines
  • an API key's last-used-from address
  • the api_key_rejected, api_key_created and api_key_revoked log lines

The Exclude your IP filter on the log pages looks your address up the same way.

X-Forwarded-For is a plain header any client can send. The app reads it only when the connection comes from an address in APP_TRUSTED_PROXIES, and otherwise uses the connection's own address. It then walks the header from the right and stops at the first address outside the list, which is the client. Every address inside the range can put any address it likes in the header, so keep the range tight.

If APP_TRUSTED_PROXIES is empty behind a proxy, or doesn't include the proxy that connects to the app, all of these record the proxy's address. A fail2ban or CrowdSec filter on the login log then bans your proxy, and Exclude your IP shows Needs APP_TRUSTED_PROXIES instead of filtering. A list with only Cloudflare's ranges misses it too, because your reverse proxy opens the connection to GeoMetrikks, not Cloudflare. 172.64.0.0/13 in that list is a Cloudflare range, not a Docker network.

To check your setting, open /api/v1/system/client-ip in the browser you use for GeoMetrikks. You want behindUntrustedProxy to be false and ip to be your own public address. When behindUntrustedProxy is true, ip is the address your proxy connected from, which is the address or subnet missing from APP_TRUSTED_PROXIES.

The list has to cover every hop that adds to X-Forwarded-For before the request reaches the app:

  • nginx and SWAG with real_ip set up rewrite the peer at the proxy, so the chain they pass on already ends in the visitor. The Docker range alone is enough.
  • When Cloudflare connects to Traefik directly, add Cloudflare's ranges next to Traefik's network, or the app stops at the Cloudflare node and records it.
  • Behind a Cloudflare Tunnel, add the address cloudflared connects from.

The app never reads CF-Connecting-IP. Behind Cloudflare the visitor reaches it only through X-Forwarded-For. GeoMetrikks behind Traefik and Cloudflare Tunnel have the details.

APP_TRUSTED_PROXIES has no effect on how the log parser reads your proxy's access log files.

Pin the Docker subnet

Docker picks a network's subnet when it creates the network. After docker compose down and up, the network can come back on another subnet, and the app goes back to recording the proxy's container address. Pin the subnet in the compose file:

networks:
  default:
    ipam:
      config:
        - subnet: 172.30.0.0/24

Pick a range that no other Docker network and nothing on your LAN uses. Docker hands out ranges such as 172.18.0.0/16 to new networks on its own, so one of those is often taken already, and a pinned range that overlaps another network makes docker compose up fail. docker network ls and docker network inspect <name> show the networks in use. For a network you create with docker network create, pin it there with --subnet.

WebSockets

The live feeds /ws/live, /ws/crowdsec and /ws/logs need the proxy to pass the Upgrade and Connection headers. Both samples below do. On an idle connection the app sends an empty frame every 30 seconds, which is under nginx's default proxy_read_timeout of 60 seconds, so the proxy doesn't close an idle feed and you don't need to raise the timeout.

SWAG

For linuxserver SWAG, save this as /config/nginx/proxy-confs/geometrikks.subdomain.conf:

## Version 2025/07/18
# make sure that your geometrikks container is named geometrikks
# make sure that your dns has a cname set for geometrikks

server {
    listen 443 ssl;
#    listen 443 quic;
    listen [::]:443 ssl;
#    listen [::]:443 quic;

    server_name geometrikks.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    # enable for ldap auth (requires ldap-location.conf in the location block)
    #include /config/nginx/ldap-server.conf;

    # enable for Authelia (requires authelia-location.conf in the location block)
    #include /config/nginx/authelia-server.conf;

    # enable for Authentik (requires authentik-location.conf in the location block)
    #include /config/nginx/authentik-server.conf;

    # enable for Tinyauth (requires tinyauth-location.conf in the location block)
    #include /config/nginx/tinyauth-server.conf;

    location / {
        # enable the next two lines for http auth
        #auth_basic "Restricted";
        #auth_basic_user_file /config/nginx/.htpasswd;

        # enable for ldap auth (requires ldap-server.conf in the server block)
        #include /config/nginx/ldap-location.conf;

        # enable for Authelia (requires authelia-server.conf in the server block)
        #include /config/nginx/authelia-location.conf;

        # enable for Authentik (requires authentik-server.conf in the server block)
        #include /config/nginx/authentik-location.conf;

        # enable for Tinyauth (requires tinyauth-server.conf in the server block)
        #include /config/nginx/tinyauth-location.conf;

        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app geometrikks;
        set $upstream_port 8000;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }
}

SWAG finds the app by the name in $upstream_app, so SWAG and GeoMetrikks have to share a Docker network. When SWAG runs in its own compose stack, create a network both stacks join, and pin the subnet on it instead of on the default network:

docker network create --subnet 172.30.0.0/24 proxy

Add it to the app service next to the default network, which the app still needs to reach the database, and add it to the SWAG service the same way:

services:
  app:
    networks:
      - default
      - proxy

networks:
  proxy:
    external: true

The app also has to answer to geometrikks on it. The shipped compose file sets hostname: geometrikks on the app service but no container_name, and the hostname alone doesn't make the name resolve for other containers. Without a fix, SWAG can't find the upstream and answers with a 502. Either add container_name: geometrikks to the app service:

services:
  app:
    container_name: geometrikks

or set $upstream_app to app, the compose service name. The service name resolves on every network the service joins, but on a shared network another stack's app service answers to it too.

SWAG reaches the app over the Docker network, so the app doesn't need a published port. Remove the ports: entry from the app service, or anyone who can reach the host on port 8000 gets around SWAG.

SWAG's stock proxy.conf already sends the WebSocket upgrade and X-Forwarded-For headers. Set APP_TRUSTED_PROXIES to the subnet of the network SWAG shares with the app, 172.30.0.0/24 in the example above.

Plain nginx

For an nginx install that terminates TLS in front of the app:

# The Connection header must be "upgrade" for WebSocket handshakes and
# "close" otherwise; this map picks the right value per request.
map $http_upgrade $connection_upgrade {
    default upgrade;
    ""      close;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name geometrikks.example.com;

    ssl_certificate     /etc/nginx/ssl/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # WebSocket upgrade for /ws/live, /ws/crowdsec and /ws/logs
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

Point proxy_pass at wherever the app runs. Which address to trust depends on where the app runs:

  • With the app outside Docker, or in a container on the host network, and nginx on the same machine, set APP_TRUSTED_PROXIES=127.0.0.1.
  • With the shipped compose file, nginx connects to 127.0.0.1:8000, but the request reaches the container from the gateway of its Docker network, such as 172.18.0.1. With only 127.0.0.1 in the list, the login log and API keys record that gateway address for every request. Trust the gateway instead. docker network inspect geometrikks_default shows it in the Gateway field; the network takes its name from the compose folder, geometrikks in the Quickstart. Pin the subnet as in Pin the Docker subnet, so the gateway keeps its address.

The shipped compose file publishes port 8000 on every interface, so anyone on your LAN can reach the app without going through nginx. With nginx on the host, publish the port on loopback only:

services:
  app:
    ports:
      - "127.0.0.1:8000:8000"

Before you expose it to the internet

  • The shipped compose file publishes port 8000 on every interface, which lets anyone who reaches the host skip the proxy and any auth portal in it. Publish it as 127.0.0.1:8000:8000 when the proxy runs on the host, or remove ports: when the proxy shares a Docker network with the app.
  • /schema, the interactive API docs, and /health need no login. To keep them private, block them at the proxy with an nginx location rule or your auth portal.
  • GeoMetrikks has no login rate limit of its own, so nothing in the app slows down password guessing. Run fail2ban or CrowdSec against the login_failed lines in the login log, or against your proxy's access log, to ban guessers at the edge. The login log describes the file.
  • Set APP_AUTH_DISABLED=true only when an authenticating proxy such as Authelia or Authentik sits in front of the app. Anyone who reaches the app's port without going through that proxy can then use every API action. See Turning the login off.
  • An API key works without the login form, so treat it like a password. Give each script its own key, use the Read scope unless the script has to change something, such as banning an IP, set an expiry, and revoke keys you no longer use. A rejected key shows up in the login log as api_key_rejected, not login_failed, so a filter for failed logins ignores it. See API keys.

On this page