Ingress-nginx: Support for Angular and custom nginx

Created on 19 Mar 2019  Â·  4Comments  Â·  Source: kubernetes/ingress-nginx

Hello,
I am trying to deploy a Kubernetes cluster on GCloud.
This is a MEAN application (Mongo, Express, Angular & Node).

My problem is when I try to access my client, I get an Angular error:
Uncaught SyntaxError: Unexpected token < inline.1a152b6….bundle.js:1

This error comes from the fact that I have to customize nginx for SPA (Single Page Application), using :
server { listen 80; location / { root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html =404; } }

Here is my ingress.yaml :

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: client
          servicePort: 80
      - path: /api/*
        backend:
          serviceName: service
          servicePort: 3000

My question: How can I customize the nginx generated by ingress to add this specific configuration?

Thanks !

Most helpful comment

This github issue is currently the top result when googling "nginx ingress try_files".

There are no local files in the ingress controller. For that reason, try_files is not a valid directive here. Keep in mind the ingress controller acts as a reverse proxy, i.e. only forward requests to the service defined in the ingress rule.

All 4 comments

Closing. You are using an invalid syntax with the rewrite-target annotation. Please check https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target

Also, please use the template issue next time you open an issue.

This github issue is currently the top result when googling "nginx ingress try_files". Could someone please answer OP's question more effectively?

This github issue is currently the top result when googling "nginx ingress try_files".

There are no local files in the ingress controller. For that reason, try_files is not a valid directive here. Keep in mind the ingress controller acts as a reverse proxy, i.e. only forward requests to the service defined in the ingress rule.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smeruelo picture smeruelo  Â·  3Comments

c-mccutcheon picture c-mccutcheon  Â·  3Comments

sophaskins picture sophaskins  Â·  3Comments

lachlancooper picture lachlancooper  Â·  3Comments

natemurthy picture natemurthy  Â·  3Comments