nginx ingress and SPA sites
- 1 minutes read - 161 wordsSeveral months ago, I resolved the issue "404 Error on refresh with SPA" by using nginx try_files directive, this time it was quite different as the apps were deployed into kubernetes. I tried nginx.ingress.kubernetes.io/use-regex:true and nginx.ingress.kubernetes.io/rewrite-target: /$1. To avoid to block others to others to use staging environment, I setup an skaffold local development environment to troubeshooting the issue. I tried following annotation as well.
nginx.ingress.kubernetes.io/configuration-snippet: |
try_files $uri $uri/ /index.html;
I knew it definitely works if I directly put the "try_files $uri $uri/ /index.html;" directive into "/etc/nginx/conf.d/default.conf" of my serivces' pods. It indeed works after I put that way. Then what’s the reason? Here is my reply to the issue at stackoverflow.
As nginx ingress controller is in another isolated pod, the generated nginx rules in nginx ingress controller can’t detect files and resources on your services. It just forward the requests to your services. The proper location to put the try_files directive should be in the your service’s pods.