<p>I'm new to kubernetes and nginx, and am having trouble understanding how to implement Ingress (nginx-ingress) for my particular use case.</p>
<p>I want to expose the pgadmin PostgreSQL admin tool from my cluster.</p>
<p>I have other applications exposed via nginx-ingress from my cluster and I like each to hang off its own subdirectory e.g.:</p>
<ul>
<li>myserver.com/purchasing/index.html</li>
<li>myserver.com/sales/index.html</li>
</ul>
<p>I have a problem doing this with pgadmin (although the problem would no doubt apply equally to other apps that behave in the same way)</p>
<p>I have set up an Ingress rule to capture and route accordingly:</p>
<pre><code>  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2

  rules:
  - http:
      paths:
        - path: /pgadmin4(/|$)(.*)

</code></pre>
<p>it does the routing and the backend is hit.</p>
<p>However when pgadmin then does a redirect, I lose the pgadmin/ from the redirect URl i.e.</p>
<ul>
<li>I send a GET to myserver.com/pgadmin</li>
<li>I receive a 302 redirect to myserver.com/login</li>
</ul>
<p>whereas I want redirecting to:</p>
<ul>
<li>myserver.com/<strong>pgadmin</strong>/login</li>
</ul>
<p>What pieces am I missing to achieve this - it feels like it should be simple?</p>
<p>Thanks</p>

<p>Had same kind of requirement for me, solved it by adding  <code>X-Script-Name</code> in annotations</p>
<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header X-Script-Name /pgadmin;
</code></pre>
<p>The full Ingress file looks like mentioned below.</p>
<p>Note: This is my test environment, so I am not enabling SSL certs, In your case, you may need to enable SSL settings</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-resource
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot; 
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header X-Script-Name /pgadmin;
spec:
  rules:
  - host: &quot;34.70.247.68.nip.io&quot;
    http:
      paths:
      - pathType: ImplementationSpecific
        path: /pgadmin
        backend:
          service:
            name: pgadmin-service
            port:
              number: 80
</code></pre>
<p>Reference: <a href="https://github.com/helm/charts/issues/21046#issuecomment-591840105" rel="nofollow noreferrer">https://github.com/helm/charts/issues/21046#issuecomment-591840105</a></p>
