【发布时间】:2020-09-13 14:58:56
【问题描述】:
我们已经为我们的应用程序配置了 kubernetes 环境。其中有一个主服务器,两个从服务器,nginx 用作网络服务器。在访问我们应用程序的 url 时,得到 cors 错误。我已按照 kubernetes 文档(https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/)设置后端和前端之间的连接,您可以在下面找到所有这些详细信息。这里没有提及 yamls 文件的全部详细信息,如果遗漏任何内容,请告知。
这是我遇到的错误。
Access to XMLHttpRequest at 'http://andy.fin.com:9090/configuration/api/v1/configuration' from origin 'http://172.16.198.102:32603' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
#nginx configuration
upstream zuul {
server zuul;
}
location / {
proxy_pass http://andy.fin.com:9090/;
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-Proto "http";
proxy_set_header Origin "http://localhost:32603";
proxy_set_header Referer "http://localhost:32603";
proxy_hide_header 'Access-Control-Allow-Origin';
}
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: zuul
tier: frontend
replicas: 1
template:
metadata:
labels:
app: zuul
tier: frontend
spec:
containers:
- name: nginx
image: nginx
---
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
selector:
app: zuul
tier: frontend
ports:
- protocol: "TCP"
port: 80
targetPort: 80
type: LoadBalancer
apiVersion: apps/v1
kind: Deployment
metadata:
name: zuul-routing
spec:
selector:
matchLabels:
app: zuul
tier: backend
replicas: 1
template:
metadata:
labels:
app: zuul
tier: backend
spec:
containers:
- env:
---
apiVersion: v1
kind: Service
metadata:
name: zuul
spec:
selector:
app: zuul
tier: backend
ports:
- protocol: TCP
port: 9090
targetPort: http
【问题讨论】:
标签: nginx kubernetes kubernetes-ingress nginx-reverse-proxy