致力于使用nginx负载平衡器托管前端和后端服务器。我正在使用docker compose从Amazon ECR中拉出,然后运行容器。泊坞窗容器可以单独工作,但是我正在努力将它们之间链接起来,然后使用nginx路由到不同的服务器。
这是docker compose文件
version: '3'
services:
backend:
image: ecr-backend
ports:
- "1235:1235"
networks:
- gg-internal
frontend:
image: ecr-frontend
ports:
- "8081:80"
networks:
- gg-internal
loadbalancer:
image: ecr-loadbalancer
ports:
- "80:80"
- "8080:8080"
networks:
- gg-internal
networks:
gg-internal:
还有nginx配置
worker_processes 1;
events { worker_connections 1024; }
http {
upstream front {
server frontend;
}
upstream backserver {
server backend;
}
sendfile on;
server {
listen 80;
location /socket.io {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://backserver/socket.io/;
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-Host $server_name;
}
location / {
proxy_pass http://front;
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-Host $server_name;
}
location /api {
proxy_pass http://backserver:1235/api/;
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-Host $server_name;
}
}
}
它从前端服务器接收前端页面,但不会将/ api重新路由到后端。
任何帮助将不胜感激:)