<p>We are moving to kubernetes and we are totally new to it.</p>
<p>In our current mono service setup we have: Nginx -&gt; Web application. These way we can protect some static assets via authentication in the web application and use internal and X-Accel-Redirect of Nginx to serve static files after authentication takes place.</p>
<p>Now in kubernetes we have Ingress and behind these services:</p>
<ul>
<li>web app</li>
<li>private static service</li>
</ul>
<p>Is there a way to tell in ingress from the web application to &quot;redirect&quot; the request as we kind of do with sendfile, so that the private static service will reply to it? Or somehow to achieve protecting our static while keeping the static service separate and independent in kubernetes setup?</p>
<p>We kind of made it work by chaining the private static service in front of the web application, but it feels there must be a better way to do it.</p>

meili
<p>Here is how I managed to make it work.</p>
<p>I created two ingresses.
First:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
        internal;
    nginx.ingress.kubernetes.io/rewrite-target: /some/path/$1
  name: static-service-internal
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: private-static-service
          servicePort: 80
        path: /protected/(.*)
</code></pre>
<p>and second service:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
  name: web-app
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: web-app
          servicePort: 80
        path: /
</code></pre>
<p>What you see above is supposed to work as in <a href="https://www.nginx.com/resources/wiki/start/topics/examples/xsendfile/" rel="nofollow noreferrer">this example from nginx documentation</a></p>
<p>When receiving <code>X-Accel-Redirect: /protected/iso.img</code> from <code>web-app</code> then it will request <code>/some/path/iso.img</code> from <code>private static service</code>.</p>
<p>Let me know if this solves you problem.</p>
