Search code examples
dockerphpmyadmin

Can't connect docker phpmyadmin with nginx


I am trying to deploy phpMyAdmin on my ubuntu machine. I am getting nginx 404 error for phpMyAdmin when trying to go https://mydomain/phpmyadmin/

docker-compose.yaml

version: '3'
services:
  django:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8000:8000"  # Adjust the port as needed
    depends_on:
      - db
      - redis
    environment:
      - MYSQL_HOST=db
      - MYSQL_PORT=3306
      - MYSQL_DB=mydb
      - MYSQL_USER=myuser
      - MYSQL_PASSWORD=mypassword
      - REDIS_HOST=redis
    command: python manage.py runserver 0.0.0.0:8000
    

  db:
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: mypassword
      MYSQL_DATABASE: mydb
      MYSQL_USER: myuser
      MYSQL_PASSWORD: mypassword
    volumes:
      - mysql_data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    restart: always
    ports:
      - "8082:80"  # Adjust the port as needed
    environment:
      PMA_HOST: db
      PMA_ABSOLUTE_URI: localhost:8082/phpmyadmin/
      MYSQL_USER: myuser 
      MYSQL_PASSWORD:mypassword
    depends_on:
      - db

  redis:
    image: redis:latest
    restart: always

volumes:
  mysql_data:

my nginx:

server {
    listen 80;
    server_name  mydomain;

    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /phpmyadmin/ {
        proxy_pass http://localhost:8081;

    }
}

my all container are running without any error

I also tried

location /phpmyadmin/ {
        proxy_pass http://127.0.0.1:8081;

    }

update 1 here my phpmyadmin running on port 8081

 phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    restart: always
    ports:
      - "8081:80"  # Adjust the port as needed
    environment:
      PMA_HOST: db
      PMA_PORT: 3307
      PMA_ABSOLUTE_URI: localhost:8081/phpmyadmin/
      MYSQL_USER: myuser  # Set the non-root user for authentication
      MYSQL_PASSWORD: mypass  # Set the password for the non-root user
    depends_on:
      - db

my nginx config

location /phpmyadmin/ {
    proxy_pass http://127.0.0.1:8081;

}

but still now getting 404 nginx. here my phpMyAdmin logs

root@4wgo:/etc/nginx/sites-available# docker logs 754b1eec2bae
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.25.0.4. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.25.0.4. Set the 'ServerName' directive globally to suppress this message
[Sun Mar 24 18:23:41.606791 2024] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.57 (Debian) PHP/8.2.8 configured -- resuming normal operations
[Sun Mar 24 18:23:41.607001 2024] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
172.25.0.1 - - [24/Mar/2024:18:25:24 +0000] "GET /phpmyadmin/ HTTP/1.0" 404 453 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
172.25.0.1 - - [24/Mar/2024:18:25:57 +0000] "GET /phpmyadmin/ HTTP/1.0" 404 453 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"

Solution

  • Things just doesn't match.

      phpmyadmin:
        image: phpmyadmin/phpmyadmin:latest
        restart: always
        ports:
          - "8082:80" # Note 8082
    
    location /phpmyadmin/ {
            proxy_pass http://127.0.0.1:8081; # Note 8081
    
        }
    

    so your pma container listens on 8082 and your nginx upstream sends to 8081