我正在通过头盔在本地minikube集群中运行react前端和golang后端。这是一个基于客户端-服务器体系结构的基本系统。当前端对后端的请求没有到达后端时。
错误预览:
Failed to load resource. The server with the specific hostname could not be found
。
标头:
Summary
URL: http://service-two/v1/admin/languages/json/en
Status: —
Source: —
Initiator:
request.js:150
Request
Origin: http://_._._._:30211
Referer: http://_._._._:30211/
Accept: */*
__
Response
No response headers
Dockerfile
(用于前端)。
FROM node:alpine as builder
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx
EXPOSE 3000
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/build /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
nginx.conf
进行反应
server {
listen 3000;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /v1/auth {
proxy_pass http://service-one:8000/;
}
location /v1/admin {
proxy_pass http://service-two:8000/;
}
}
configmap.yaml
(用于前端)
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "name" . }}-config
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
component: "{{ .Values.service.name }}"
heritage: "{{ .Release.Service }}"
release: "{{ .Release.Name }}"
data:
default.conf: |-
window.config = {
frontend: {
main_panel: "{{ .Values.frontend.mainPanel }}"
},
backend: {
service_one: "{{ .Values.frontend.serviceOne }}",
service_two: "{{ .Values.frontend.serviceTwo }}"
}
}
/etc/resolv.conf
详细信息
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
我可以curl
从前端到后端都没有问题。似乎Nginx反向代理似乎不起作用。我该如何解决?