Nginx config as reverse proxy

I need to configure nginx as reverse proxy. It should allow access to /phpmyadmin with a reverse proxy to private_ip:5000. This is part of nginx.conf:

location ~ /phpmyadmin {
   rewrite ^.*\/phpmyadmin(\/?)(.*)$ /$2 break;
   proxy_pass        https://192.168.99.6:5000;
   proxy_redirect     off;
   proxy_set_header   Host $host;
}

And this config works except in cases:

  1. https://192.168.99.6:5000/phpmyadmin. But with a / at the end, that's okay.
  2. I get a 404 error after logging in, but if I press "back" everything is fine.
  3. I also get 404 error after logging out.

Please help me fix this. All services are in the k8s cluster.


It's not immediately obvious what the goal is here.

If the backend service is listening with a URI that matches /phpmyadmin and you have a location block for /phpmyadmin in your nginx config, then it should be entirely sufficient to simply put:

location /phpmyadmin {
  proxy_pass https://192.168.99.6:5000;
  proxy_set_header Host $host;
}

If the goal is to drop the /phpmyadmin URI segment, then something like:

location /phpmyadmin/ {
  proxy_pass https://192.168.9.6:5000/;
  proxy_set_header Host $host;
}

From my understanding of your description you don't actuallt need the rewrite at all.