Score:0

How to serve phpMyAdmin to localhost/phpMyAdmin instead of localhost:8080 using nginx in docker

gb flag

In my project, I am using Django and nginx, but I want to manage my cloud databases through phpmyadmin.

Django is working fine but I can't do the same with phpmyadmin because it is running in apache at localhost:8080, when I want it to run in nginx at localhost/phpmyadmin.

here is the docker-compose.yml

version: "3.9"
   
services:

  web:
    restart: always
    build:
      context: .
    env_file:
      - .env
    volumes:
      - ./project:/project
    expose:
      - 8000
      
  nginx:
    restart: always
    build: ./nginx
    volumes:
      - ./static:/static
    ports:
      - 80:80
    depends_on:
      - web

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    restart: always
    environment:
      PMA_HOST: <host_address>
      PMA_USER: <user>
      PMA_PASSWORD: <password>
      PMA_PORT: 3306
      UPLOAD_LIMIT: 300M
    ports:
      - 8080:80

and nginx default.conf

upstream django{
    server web:8000;
}

server{
    listen 80;
    location / {
        proxy_pass http://django;
    }

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

    location /static/ {
        alias /static/;
    }
}

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.

Score:0
ru flag

You don't specify what's the ill effect you are experiencing, but perhaps the phpMyAdmin expects a host header to route requests to PMA_HOST.

You could try passing the host header in your proxy configuration:

location / {
    proxy_pass http://localhost:8080/;                                 
    proxy_buffering off; 
    proxy_set_header Host $host;
}

Word of advice: PhpMyAdmin is not known for its security and and if you look at your web server logs, you'll see a constant attempt to locate the phpMyadmin installation and check for various vulnerabilities on it.

In my opinion phpMyadmin is a development level service and should not be in production server. It is way more secure to ssh tunnel via your host to your SQL server using for example MySQL Workbench or any other suitable SQL client.

Would you install phpmyadmin on a production web server?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.