Running behind haproxy in a subdirectory ΒΆ

When you want to expose phpMyAdmin running in a Docker container in a subdirectory, you need to rewrite the request path in the server proxying the requests.

For example, using haproxy it can be done as:

frontend http     bind *:80     option forwardfor     option http-server-close      ### NETWORK restriction     acl LOCALNET  src 10.0.0.0/8 192.168.0.0/16 172.16.0.0/12      # /phpmyadmin     acl phpmyadmin  path_dir /phpmyadmin     use_backend phpmyadmin if phpmyadmin LOCALNET  backend phpmyadmin     mode http      reqirep  ^(GET|POST|HEAD)\ /phpmyadmin/(.*)     \1\ /\2      # phpMyAdmin container IP     server localhost     172.30.21.21:80 

When using traefik, something like following should work:

defaultEntryPoints = ["http"] [entryPoints]   [entryPoints.http]   address = ":80"     [entryPoints.http.redirect]       regex = "(http:\\/\\/[^\\/]+\\/([^\\?\\.]+)[^\\/])$"       replacement = "$1/"  [backends]   [backends.myadmin]     [backends.myadmin.servers.myadmin]     url="http://internal.address.to.pma"  [frontends]    [frontends.myadmin]    backend = "myadmin"    passHostHeader = true      [frontends.myadmin.routes.default]      rule="PathPrefixStrip:/phpmyadmin/;AddPrefix:/" 

You then should specify PMA_ABSOLUTE_URI in the docker-compose configuration:

version: '2'  services:   phpmyadmin:     restart: always     image: phpmyadmin/phpmyadmin     container_name: phpmyadmin     hostname: phpmyadmin     domainname: example.com     ports:       - 8000:80     environment:       - PMA_HOSTS=172.26.36.7,172.26.36.8,172.26.36.9,172.26.36.10       - PMA_VERBOSES=production-db1,production-db2,dev-db1,dev-db2       - PMA_USER=root       - PMA_PASSWORD=       - PMA_ABSOLUTE_URI=http://example.com/phpmyadmin/