0

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.

1

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.

1
  • This is a training project that aims to understand all of these technologies. Without rewriting, in the first case, it turned out 404, in the second - 502. – afjord Nov 2 '20 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.