<p>I am using <a href="https://github.com/kubernetes/ingress-nginx/" rel="noreferrer">this ingress controller</a> and would like to setup a s3 proxy to some bucket. If I call in a browser the url </p>

<pre><code>https://my-kube-server.org/img/dog.jpg 
</code></pre>

<p>I expect to see/download the image at </p>

<pre><code>https://s3.eu-central-1.amazonaws.com/mybucket123/pictures/dog.jpg
</code></pre>

<p>I can setup a rewrite rule and point to an external service as explained in <a href="https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite" rel="noreferrer">this example</a>:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: s3-proxy
spec:
  type: ExternalName
  externalName: s3.eu-central-1.amazonaws.com
  headers:
  - host: s3.eu-central-1.amazonaws.com
</code></pre>

<p>But I get errors from aws because it's required to have "Host:s3.eu-central-1.amazonaws.com" in the header. I cannot set this header neither in the s3-proxy service definition nor in the ingress rule (<a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/nginx-configuration/annotations.md#configuration-snippet" rel="noreferrer">configuration-snippet</a> doesn't work because it will add another Host header after it's set already in the nginx.conf pod.</p>

<p>My solution is to take the whole location block for this ingress rule and to include it as a <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/nginx-configuration/annotations.md#server-snippet" rel="noreferrer">server-snippet</a>, which is pretty brute force. </p>

<p>Another option is to have an nginx pod+service behind ingress that takes care of setting the right headers. So the flow would be request -> ingress-controller -> nginx -> s3.</p>

<p>Has anybody an idea how to proxy s3?</p>

Gismo Ranas
<p>If you need to use the <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/nginx-configuration/annotations.md#server-snippet" rel="noreferrer">server-snippet</a> solution. Something similar to the following will add a custom <code>location</code> block to the Nginx ingress config. This is especially useful if you have other custom requirements for the Nginx ingress.</p>
<pre><code>metadata:
  annotations:
    &lt;other annotations&gt;
    nginx.ingress.kubernetes.io/server-snippet: |
      location &quot;/img/&quot; {
        proxy_pass http://s3.eu-central-1.amazonaws.com/mybucket123/pictures/;
        proxy_set_header Host s3.eu-central-1.amazonaws.com;
      }
</code></pre>
<p>Also, if you are reverse proxying to an endpoint that provides limited logging (AWS S3). The Nginx <a href="http://nginx.org/en/docs/http/ngx_http_mirror_module.html#mirror" rel="noreferrer">mirror</a> feature can help debug what requests are being sent. Add an additional annotation to the Ingress controller and specify a system where you can monitor the requests.</p>
<pre><code>nginx.ingress.kubernetes.io/mirror-target: &quot;http://my-debug-target/&quot;
</code></pre>
