[英]Vuejs into kubernetes cluster and nginx ingress returns 404 when refreshed
I'm trying to run a Vue.js frontend service into nginx-ingress enabled kubernetes cluster.我正在尝试将 Vue.js 前端服务运行到启用了 nginx-ingress 的 kubernetes 集群中。 The application has 4 routes, /, /foo/, /bar and /about.该应用程序有 4 个路由,/、/foo/、/bar 和 /about。 If I access the application and refresh the page in any route besides /, I get a 404 error from nginx ingress.如果我在除 / 之外的任何路由中访问应用程序并刷新页面,我会从 nginx 入口收到 404 错误。
I'm using kubernetes version v1.18.2 (both client and server).我正在使用 kubernetes 版本 v1.18.2(客户端和服务器)。 The cluster was created by the kind (kubernetes in docker program) and I setup the ingress following their documentation at https://kind.sigs.k8s.io/docs/user/ingress/#ingress-nginx .集群是由那种(docker 程序中的 kubernetes)创建的,我按照他们在https://kind.sigs.k8s.io/docs/user/ingress/#ingress-nginx的文档设置了入口。 The example application I'm using is this one: https://github.com/ovitor/foo我正在使用的示例应用程序是这个: https://github.com/ovitor/foo
Here are the deployments, services and ingress used.以下是使用的部署、服务和入口。
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: foo
name: foo
spec:
replicas: 1
selector:
matchLabels:
app: foo
template:
metadata:
labels:
app: foo
spec:
containers:
- image: vcml10/foo:latest
name: foo
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
labels:
app: foo
name: foo
spec:
ports:
- name: http
port: 80
protocol: TCP
selector:
app: foo
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: foo-ingress
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: foo
servicePort: 80
What I'm doing wrong?我做错了什么?
I think that's because you have path only for /
.我认为那是因为您只有/
的路径。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: foo-ingress
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: foo
servicePort: 80
If you want to make it work for / /foo/ /bar and /about
you would have to add additional paths.如果你想让它适用于/ /foo/ /bar and /about
你将不得不添加额外的路径。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: foo-ingress
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: foo
servicePort: 80
- path: /foo
backend:
serviceName: foo
servicePort: 80
- path: /bar
backend:
serviceName: foo
servicePort: 80
- path: /about
backend:
serviceName: foo
servicePort: 80
OR或者
Use regex as mentioned in the nginx ingress documentation使用 nginx 入口文档中提到的正则表达式
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: test.com
http:
paths:
- path: /foo/.*
backend:
serviceName: test
servicePort: 80
Additionally you can take a look at rewrite annotation .此外,您可以查看rewrite annotation 。
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.