<p>I have two nginx web servers set up. One is set up on AWS Elastic Beanstalk, the other on Kubernetes using the stable/nginx-ingress helm chart. </p>

<p>The Elastic Beanstalk webserver forwards traffic from all subroutes of my domain to the Kubernetes nginx webserver. I can verify these are being forwarded correctly by checking the logs from the Kubernetes nginx. I use an Ingress resource to make sure this traffic is being forwarded to the right Kubernetes service.</p>

<p><strong>Here is the problem</strong>:
One of the two routes, the main <code>/</code> route, is forwarded to the correct service and returns a 200. The other route, <code>/eks-test</code>, is supposed to route to the same service, but returns a 404. <strong>How is this possible?</strong></p>

<p><strong>Specs</strong>:</p>

<p>The nginx on Kubernetes is running nginx <code>0.25.1</code>. I am running Kubernetes on AWS EKS version 1.14.</p>

<p>Nginx logs:</p>

<pre><code>172.16.10.103 - [172.16.10.103] - - [12/Sep/2019:08:05:09 +0000] "GET / HTTP/1.0" 200 8 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36" 703 0.004 [default-eks-test-repo-80] [] 172.16.10.100:8080 8 0.004 200 90dfa37364a5c43e57f12c5fb1a2d86f
172.16.40.108 - [172.16.40.108] - - [12/Sep/2019:08:05:12 +0000] "GET /eks-test HTTP/1.0" 404 9 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36" 730 0.002 [default-eks-test-repo2-80] [] 172.16.43.125:8080 9 0.004 404 ef1c81bba75dff2bdd2376799aa93c56
</code></pre>

<p>First nginx config (Elastic Beanstalk):</p>

<pre><code>server {
    listen 80;

    server_name my.domain.com;

    location / {

        proxy_pass http://internal.my.domain.lan/;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
</code></pre>

<p>Kubernetes Ingress resource:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: internal
  name: eks-test
  namespace: default
spec:
  rules:
    - host: my.domain.com
      http:
        paths:
          - path: /
            backend:
              serviceName: eks-test-repo
              servicePort: 80
          - path: /eks-test
            backend:
              serviceName: eks-test-repo
              servicePort: 80
</code></pre>

<p>Kubernetes Service:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: eks-test-repo
  namespace: default
  labels:
    name: eks-test-repo
spec
  ports:
    - port: 80
      targetPort: 80
  selector:
    app: eks-test-repo
  type: ClusterIP
</code></pre>

<p>Nginx helm chart values (ones that are not default):</p>

<pre><code>controller.ingressClass: internal
</code></pre>

Lars S
<p>The answer to this question can be found <a href="https://superuser.com/questions/1481815/why-does-nginx-return-404-on-my-kubernetes-ingress-route">here</a>.</p>

<p>Basically, the paths were not being rewritten to <code>/</code>, but the webservers in the pods were only listening on the root path. Adding the <code>nginx.ingress.kubernetes.io/rewrite-target: /</code> annotation fixed the problem.</p>
