<p>Currently I am trying to Migrate a site that was living on an Apache Load balanced Server to my k8s cluster. However the application was set up strangely with a proxypass and proxyreversepass like so:</p>

<pre><code>ProxyPass /something http://example.com/something
ProxyPassReverse /something http://example.com/something
</code></pre>

<p>And I would like to mimic this in an Nginx Ingress</p>

<p>First I tried using the <code>rewrite-target</code> annotation however that does not keep the <code>Location</code> header which is necessary to get the application running again. </p>

<p>Then I tried to get the <code>proxy-redirect-to/from</code> annotation in place inside a specific location block like so:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: gpg-app-ingress
  annotations:
    nginx.ingress.kubernetes.io/proxy-redirect-from: http://originalapp.com/something
    nginx.ingress.kubernetes.io/proxy-redirect-to: http://example.com/something
spec:
  rules:
  - host: example.com
    http:
      paths:
        - path: /something
          backend:
            serviceName: example-com
            servicePort: 80
</code></pre>

<p>I would like to be able to instead use a custom <code>proxy_pass</code> variable but it doesn't seem like its possible.</p>

<p>What would be the best way to mimic this proxy pass?</p>

Pablo Marti Cordero
<p>Firstly you can use custom configuration for your nginx ingress controller, documentation can be found <a href="https://kubernetes.github.io/ingress-nginx/examples/customization/configuration-snippets/#ingress" rel="noreferrer">here</a></p>

<p>Also, if you just want to use nginx ingress controller as a reverse proxy, each ingress rule already creates <code>proxy_pass</code> directive to relevant upstream/backend service. </p>

<p>And if paths are same with your rule and backend service, then you don't have to specify rewrite rule, only just path for backend service. But if paths
are different, then take consider using <code>nginx.ingress.kubernetes.io/rewrite-target</code> annotation, otherwise you will get <code>404 backend</code> error</p>

<p>So to redirect request from which is coming to frontend <code>http://example.com/something</code> to backend <code>example-com/something</code>, your ingress rule should be similar to below</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: gpg-app-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
   #nginx.ingress.kubernetes.io/rewrite-target: /different-path
spec:
  rules:
  - host: example.com
    http:
      paths:
        - path: /something
          backend:
            serviceName: example-com
            servicePort: 80
</code></pre>

<p>For more explanation about annotations, check <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/nginx-configuration/annotations.md" rel="noreferrer">Nginx Ingress Annotations</a></p>

<p>Also, consider checking logs of nginx-ingress-controller pod via if something wrong</p>

<pre><code>kubectl logs nginx-ingress-controller-xxxxx
</code></pre>

<p>Hope it helps!</p>
