1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

nginx proxy で phpmyadmin のコンテナにアクセスできない

Posted at

以下の構成で構築していたが、/__phpmyadmin/にアクセスできなかった。

docker-compose.yml
version: '3'

services:
  app:
    build:
      context: ./docker
      dockerfile: Dockerfile
    environment:
      APP_ENV: 'DOCKER_DEV'
    working_dir: /app
    volumes:
      - '.:/app'
    extra_hosts:
      - "host.docker.internal:host-gateway"

  proxy:
    image: steveltn/https-portal:1
    ports:
      - '80:80'
      - '443:443'
    environment:
      DOMAINS: 'domain.jp -> http://app, domain.com -> http://host.docker.internal:3000'
      STAGE: 'production'
    volumes:
      - ./docker/proxy/https-portal-data:/var/lib/https-portal
      - ./docker/proxy/nginx-conf/domain.com.ssl.conf.erb:/var/lib/nginx-conf/domain.com.ssl.conf.erb:ro
    depends_on:
      - app
    extra_hosts:
      - "host.docker.internal:host-gateway"

  phpmyadmin:
    image: 'phpmyadmin/phpmyadmin'
    environment:
      PMA_HOST: 'host.docker.internal'
      PMA_PORT: '3306'
      PMA_ABSOLUTE_URI: 'https://domain.com/__phpmyadmin/'
    extra_hosts:
      - "host.docker.internal:host-gateway"

docker/proxy/nginx-conf/domain.com.ssl.conf.erb
<%# 省略 %>
    location /__phpmyadmin/ {
        proxy_pass http://phpmyadmin;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

https://domain.com/__phpmyadmin/にアクセスしても404となってしまっていた。

解決

rewrite ... を追加で解決した。

domain.com.ssl.conf.erb
<%# 省略 %>
    <%# https://github.com/phpmyadmin/docker/issues/210 %>
    location /__phpmyadmin/ {
        rewrite ^/__phpmyadmin(/.*)$ $1 break;
        proxy_pass http://phpmyadmin;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?