在我目前的设置中,当客户端从后端API请求任何东西时,浏览器控制台中会出现404错误状态:parsing_error,这是在localhost:3000/login登录尝试时发生的。我倾向于在nginx.conf中的位置块中解决问题,但在这一点上不确定,我已经尝试了许多不同的调整,但最终还是出现了其他错误。我在这个设置中缺少了什么?
nginx.conf
upstream loadbalancer {
least_conn;
server ws1:8081;
server ws2:8082;
server ws3:8083;
}
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://loadbalancer/;
proxy_buffering on;
}
}
字符串
docker-compose.yml
services:
ws1:
image: bark-mate-be
environment:
- APPID=1111
- APPPORT=8081
networks:
- loadbalancing
ports:
- "8081"
ws2:
image: bark-mate-be
environment:
- APPID=2222
- APPPORT=8082
ports:
- "8082"
networks:
- loadbalancing
ws3:
image: bark-mate-be
environment:
- APPID=3333
- APPPORT=8083
ports:
- "8083"
networks:
- loadbalancing
barkmatefrontend:
image: bark-mate-fe
ports:
- "3000:80"
networks:
- loadbalancing
depends_on:
- db
- ws1
- ws2
- ws3
db:
volumes:
- barkMate_db:/data/db
image: mongo:latest
ports:
- "27017:27017"
volumes:
barkMate_db:
networks:
loadbalancing:
型
Dockerfile-client
FROM node:current-alpine as build
WORKDIR /app
COPY package*.json /app/
RUN npm install
RUN npm ci --production
COPY . .
RUN npm run build
FROM nginx:alpine-slim
COPY --from=build /app/build/ /usr/share/nginx/html
COPY --from=build /app/nginx/nginx.conf /etc/nginx/conf.d/default.conf
型
Dockerfile服务器
FROM node:16
RUN mkdir -p /app
WORKDIR /app
COPY package*.json ./
RUN npm install --silent
COPY . .
EXPOSE 8080
CMD ["node", "server.js"]
型
1条答案
按热度按时间3gtaxfhh1#
我已经修复了错误,由于前端映像构建时间,此设置很难测试。对于每个Web服务器映像ie(ws 1,ws 2...)端口在docker-compose. yml中Map不正确。例如,之前是
字符串
现在是
型
因此,将外部容器端口从内部容器8080Map到8081,内部容器8080暴露在每个Web服务器使用的bark-mate-be映像中。我还删除了proxy_pass URL的尾随正斜杠,不确定这是否有区别,但它可能在我之前的尝试中抛出了一个误导性错误。