phpMyAdmin inside docker container via nginx reverse proxy phpMyAdmin inside docker container via nginx reverse proxy docker docker

phpMyAdmin inside docker container via nginx reverse proxy


Be sure to include the rewrite:

location  ~ \/pma {  rewrite ^/pma(/.*)$ $1 break;  proxy_set_header X-Real-IP  $remote_addr;  proxy_set_header X-Forwarded-For $remote_addr;  proxy_set_header Host $host;  proxy_pass http://localhost:8081;}

You'll also want to set the PMA_ABSOLUTE_URI environment variable in your docker-compose.yml:

PMA_ABSOLUTE_URI: https://yourdomain.com/pma/

Provided you're running 4.6.5 or later of the docker phpmyadmin you should be set. To update you can docker pull to pull down the latest. i.e.

docker pull phpmyadmin/phpmyadmin


Just remove the ending backslash of /pma/:

location /pma {                   proxy_pass http://localhost:8081/;                                     proxy_buffering off;                                     }

With it the browser treats it as a directory and request for assets accordingly, which is unexpected for PMA.


There's not a lot that can be done. Problem is that phpmyadmin is serving its pages from localhost, and even if nginx translates accesses from http://servm3/pma to http://localhost, all links in HTML content ignore the lattest and, even if they're relative, they don't take into account the /pma part. So, all those 404 errors you're seeing are from resources that, inside HTML, are referenced as relative links like styles.css, that when referenced/clicked become http://servm3/styles.css, that doesn't exist in the server.

Unfortunately reverse proxies work at the header level so, even if they are able to change headers like Location on the fly, they leave HTML content untouched, and hence the problems. There're workarounds involving changing HTML code on the fly, but they're not easy, are unreliable at most and they hinder performance considerably, so the only practical solution is that websites explicitly support some kind of base path setting. In this case, the solution would be that phpmyadmin Docker image allowed setting the base path using an environment variable in docker-compose.yaml, instead of defaulting to root.

Another workaround in the mean time would be not using a relative path, but a subdomain. If you're in control of DNS settings for servm3, you could use something like phpmyadmin.servm3, and proxy_pass without problems.