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 !
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.
Most helpful comment
There are no local files in the ingress controller. For that reason,
try_filesis 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.