Can't connect 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:8082;

    }
}

my all container are running without any error

I also tried

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

    }

my 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"

Hello

Did you have tried localhost (or 127.0.0.1) and not mydomain ?

I’m using phpmyadmin a lot and I access it using http://localhost:8082 (your port),

I have run on my production server not my local pc

Just because something runs in a Docker container, it isn’t necessarily a Docker issue. :slight_smile: Please, check the documentation of Nginx regarding proxy_pass

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

A request URI is passed to the server as follows:

  • If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:

location /name/ { proxy_pass http://127.0.0.1/remote/; }

  • If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI:

location /some/path/ { proxy_pass http://127.0.0.1; }

Before version 1.1.12, if proxy_pass is specified without a URI, the original request URI might be passed instead of the changed URI in some cases.

A container is just like a remote server, so unless phpmyadmin runs at /phpmyadmin, you need to add a slash character after the IP address to define the URI so the location will be replaced by the URI defined after the IP.

I also recommend reading this tutorial:

1 Like

Thanks a lot I was missing trailing slash so it should be

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


    }
``` also how to add  index and root files from docker in nginx  ??
1 Like