Nginx reverse proxy to web app in kubernetes gives 404 for static web resources

9/17/2019

Hi nginx extraordinaire's

I am using nginx as a load balancer and reverse proxy to play the role of an external-facing API gateway to interface applications and api's hosted in kubernetes. these are all exposed via ingress

enter image description here

The issue I am facing is that nginx is giving me 404s when I try to access a standard angular web app via the /test URL

See error:

enter image description here

Nginx was set up using the following config - nginx.conf

    events {
worker_connections  1024;
}

http {

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

ssl                       on;
ssl_certificate           /etc/letsencrypt/live/myhostname/fullchain.pem;
ssl_certificate_key       /etc/letsencrypt/live/myhostname/privkey.pem;

client_max_body_size      1G;

upstream k8snodes {
  server 192.168.2.10; 
  server 192.168.2.11;
}

server {
    listen                  443 ssl;

    location / {
      proxy_pass            http://k8snodes/;
      proxy_redirect        off;
      proxy_set_header      Host $host;
      proxy_set_header      X-Real-IP $remote_addr;
      proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header      X-Forwarded-Host $server_name;
      proxy_set_header      X-Forwarded-Proto $scheme;
    }

    include /etc/nginx/conf.d/*.conf;
 }

 }

Sitting behind /test is a Kubernetes ingress controller that serves the angular application. I can confirm that application can be accessed fine when directly through ingress so there is something that nginx is not happy with.

Ingress config

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  creationTimestamp: "2019-09-14T07:43:49Z"
  generation: 2
  name: test-ingress
  namespace: default
  resourceVersion: "12193067"
  selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/test- 
ingress
  uid: f8c5ea11-9caf-431e-9a18-19bd3981eece
spec:
  rules:
  - host: myhostname
    http:
      paths:
      - backend:
          serviceName: test-svc
          servicePort: 80
        path: /test
status:
  loadBalancer:
    ingress:
    - {}

Is there something I have done wrong on the Nginx config? I have other API's that are reverse proxied fine it seems to be the web applications that try to serve static files that are giving issues.

-- Keith
kubernetes-ingress
nginx
nginx-reverse-proxy

0 Answers