Docker Community Forums

Share and learn in the Docker community.

Nginx, phpmyadmin bad redirect during authorization

While entering the login and password, it throws me to the root domain:

www.example.com/phpmyadmin -> www.example.com/index.php

I need:

www.example.com/phpmyadmin -> www.example.com/phpmyadmin/index.php

my nginx.conf :

resolver 127.0.0.11 valid=15s;

server {
  listen 80;
  server_name localhost;
  set $upstream phpmyadmin:9000;

  location ^~ /phpmyadmin {
    alias /var/www/phpmyadmin/;
    index index.php;
    location ~ \.php$ {
      try_files      $uri = 404;
      include        fastcgi_params;
      fastcgi_split_path_info ^\/phpmyadmin\/(.+\.php)(.*)$;
      fastcgi_param  SCRIPT_FILENAME $fastcgi_script_name;
      fastcgi_pass   $upstream;
    }
  }
}

docker-compose.yml :

phpmyadmin:
    container_name: phpmyadmin
    depends_on:
      - mysql
    image: phpmyadmin/phpmyadmin:fpm-alpine
    environment:
      - PMA_HOST=mysql
      - MYSQL_ROOT_PASSWORD=somepass 
    volumes: 
      - phpmyadmin:/var/www/html
    networks:
      - web   

webserver:
    image: nginx:1.16.1-alpine
    container_name: webserver
    depends_on: 
      - phpmyadmin
    ports: 
      - "80:80"
      - "443:443"
    volumes:
      - phpmyadmin:/var/www/phpmyadmin
      - ./nginx-conf:/etc/nginx/conf.d
    networks: 
      - web

I searched a lot on the Internet. This problem arose among many people and many simply refused to use phpmyadmin on the subdomain. Maybe there’s finally a solution?