Inyourface
Inyourface

Reputation: 532

404 not found on phpmyadmin - nginx docker

I want to run phpmyadmin and my API on same domain using docker and nginx, as:

api => localhost:8888/ phpmyadmin => localhost:8888/phpmyadmin/

Docker config for phpmyadmin service:

phpmyadmin:
  image: phpmyadmin
  restart: always
  environment:
    PMA_ARBITRARY: 1
    PMA_HOST: mysql
    PMA_USER: ${DATABASE_USER}
    PMA_PASSWORD: ${DATABASE_PASSWORD}
  depends_on:
    - mysql

This is nginx service config:

nginx:
  image: nginx:stable-alpine
  volumes:
    - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
  depends_on:
    - api
    - phpmyadmin
  restart: always
  ports:
    - '8888:80'

And this is nginx config file:

upstream pma {
  server phpmyadmin;
}

server {
  listen 80;
  server_name localhost;
  # resolver 127.0.0.1;

  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;

    proxy_pass http://api:8889/;
    proxy_redirect off;
  }

  location ~/phpmyadmin(.*)$ {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;

    proxy_pass http://pma/$1/;
    proxy_redirect off;
  }
}

Everything works fine, I can use the API, as localhost:8888/url and it works fine. But when I request localhost:8888/phpmyadmin/, it loads it, but js and all css gives 404 not found, here's the console preview:

enter image description here

I have been scratching my head from more than 3 hours to fix this, tried my best, but it doesn't work. I am pretty much new to nginx so can anyone please help me out.

Upvotes: 1

Views: 1577

Answers (1)

U-Dev
U-Dev

Reputation: 1387

Did you try adding PMA_ABSOLUTE_URI in the docker phpmyadmin service environments? Checkout this:

PMA_ABSOLUTE_URI - the full URL to phpMyAdmin. Sometimes needed when used in a reverse-proxy configuration.

Add it like:

PMA_ABSOLUTE_URI: localhost:8888/phpmyadmin/

Please notice the last / that is very very important, if you miss it, it will not work.

Upvotes: 2

Related Questions