无法将 docker phpmyadmin 与 nginx 连接

问题描述 投票:0回答:1

我正在尝试在我的 ubuntu 机器上部署 phpMyAdmin。当尝试访问 https://mydomain/phpmyadmin/ 时,我收到 phpMyAdmin 的 nginx 404 错误

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:

我的 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;

    }
}

我的所有容器都在运行,没有任何错误

我也尝试过

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

    }
mysql docker phpmyadmin
1个回答
0
投票

事情就是不匹配。

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

    }

所以你的 pma 容器监听 8082 并且你的 nginx 上游发送到 8081

© www.soinside.com 2019 - 2024. All rights reserved.