Proxy web interface

'm trying to proxy the pgAdmin web interface using segment URLs. But I have some problems with this.

When I'm accessing the browser with the following URL -> http://localhost/pgadmin, it redirects me to the following URL -> http://localhost/login?next=%2F. This is the internal routing of pgAdmin.

I want routing to be next http://localhost/pgadmin/login?next=%2F.

Could you tell me how can I achieve this.

Here is an example of my docker-compose configuration

version: '3.7'

services:

  traefik:
   image: traefik:v2.2
   container_name: traefik
   restart: always
   networks:
            applications_network:
                ipv4_address: 172.20.1.1
   ports:
    - "80:80"
    - "8080:8080"
   command: 
    - "--api.insecure=true --providers.docker"
    - "--api.insecure=true"
    - "--providers.docker=true"
    - "--providers.docker.exposedbydefault=false"
    - "--entrypoints.web.address=:80"
    - "--log.level=debug"
   volumes:
    - "/var/run/docker.sock:/var/run/docker.sock:ro"


  pgAdmin4:
   image: dpage/pgadmin4:latest
   container_name: pgAdmin4
   restart: always
   networks:
            applications_network:
                ipv4_address: 172.20.2.1
   ports:
    - "15432:80"
   environment:
    PGADMIN_DEFAULT_EMAIL: "admin@test.com"
    PGADMIN_DEFAULT_PASSWORD: "postgres"
   labels:
      - "traefik.enable=true"
      - "traefik.http.routers.pgAdmin4.rule=Host(`localhost`)"
      - "traefik.http.middlewares.pgAdmin4-prefix.stripprefix.prefixes=/pgadmin"
      - "traefik.http.routers.pgAdmin4.middlewares=pgAdmin4-prefix"
      - "traefik.http.routers.pgAdmin4.entrypoints=web"
      - "traefik.http.routers.pgAdmin4.service=pgAdmin4"
      - "traefik.http.services.pgAdmin4.loadbalancer.server.port=80"


networks:
    applications_network:
        name: applications_network
        ipam:
            driver: default
            config:
                - subnet: 172.20.0.0/16

Thanks in advance.

1 Like

Welcome to the forums!

You will need to configure the base URL of pgadmin with your segment URL, if possible. Otherwise, you may want to consider utilizing a subdomain for this service.

Sorry to bump this two years later, but I'm now running into the exact same issue. It appears that the pgAdmin docker container does not contain any features that allow us to specify the path the webserver uses. Does Traefik not have any functionality that allows us to proxy web requests in such a way that stubborn containerized web servers will be satisfied when they rewrite paths?

Update: pgAdmin4 docker container officially has an environment variable to adjust the application path. Use -e "SCRIPT_NAME=/pgadmin4" \

The only necessary label you need now is:

labels:
  - traefik.http.routers.<name>.rule=Host(`<host>`) && PathPrefix(`/pgadmin4`)