Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpMyAdmin inside docker container via nginx reverse proxy

I installed phpMyAdmin docker image and run it with

# docker run --name phpmyadmin -d --link mariadb:db -p 8081:80 -e PMA_ABSOLUTE_URI=http://servm3/pma --restart unless-stopped phpmyadmin/phpmyadmin

Accessing http://servm3:8081 works fine. The variable PMA_ABSOLUTE_URI is for reverse proxies as seen on the docker page.

Then I set up nginx (locally installed, not inside docker) to act as a reverse proxy (working for several other apps like guacamole).

Inside my nginx.conf I have:

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

Accessing http://servm3/pma shows the favicon on the browser tab but instead of the login page only a blank page is shown. Removing the preceding "/" and restarting nginx only gives a 404.

# docker logs phpmyadmin

shows nothing except from the php and nginx service start info, nothing related to phpmyadmin.

Local nginx access log shows several 304 and 404 codes and some 200, error log is not present. Detailled log can be found here on pastebin.

I hope somebody will be able to tell me how to make nginx work as a reverse proxy for the phpMyAdmin docker container.

If some important information is missing please let me know.

like image 625
släcker Avatar asked Jun 12 '17 12:06

släcker


3 Answers

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
like image 89
Joshua Ostrom Avatar answered Nov 15 '22 07:11

Joshua Ostrom


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.

like image 2
Robert Avatar answered Nov 15 '22 07:11

Robert


Don't need rewrite.

nginx.conf:

location ^~ /pma/ {
    proxy_pass http://pma-container/;
    absolute_redirect off;
}

docker-compose.yml:

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

Notice: keep trailing slash on location, proxy_pass, PMA_ABSOLUTE_URI

like image 2
heatlai Avatar answered Nov 15 '22 07:11

heatlai