【发布时间】:2020-06-03 13:30:47
【问题描述】:
docker-compose.yml
version: "3"
services:
mongodb:
image: "mongo:latest"
nginx:
restart: always
build:
dockerfile: Dockerfile.dev
context: ./nginx
ports:
- "5000:80"
backend:
build:
dockerfile: Dockerfile.dev
context: ./backend
ports:
- "3000:3000"
volumes:
- /app/node_modules
- ./backend:/app
environment:
- MONGOHOST=cluster0-ipauv.mongodb.net
- MONGOPORT=27017
- MONGODATABASE=node-express
- MONGOUSER=USER
- MONGOPASSWORD=password
frontend:
build:
dockerfile: Dockerfile.dev
context: ./frontend
ports:
- "4200:4200"
volumes:
- /app/node_modules
- ./frontend/:/app
nginx/default.conf
upstream frontend{
server frontend:4200 weight=10 max_fails=3 fail_timeout=30s;
keepalive 32;
}
upstream backend{
server backend:3000 weight=10 max_fails=3 fail_timeout=30s;
keepalive 32;
}
server {
listen 80;
server_name frontend;
location / {
proxy_pass http://frontend;
}
location /sockjs-node {
proxy_pass http://frontend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://backend;
}
}
nginx/Dockerfile.dev
FROM nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf
我在加载 URL 时遇到的错误:http://localhost:5000
[error] 6#6: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: frontend, request: "GET / HTTP/1.1", upstream: "http://172.19.0.2:4200/", host: "localhost:5000"
【问题讨论】:
-
一个建议是使用 ngnix 服务器来部署您的前端应用程序。我怀疑你的构建没有成功。
-
看看这个如果这对你有帮助serverfault.com/questions/317393/…
-
感谢您的链接,我检查了但看起来这对我不起作用。您还可以详细说明用户 Nginx 服务器部署前端应用程序吗?因为我是码头工人的新手。另外,当我运行“docker-compose up --build”时,我没有收到任何错误。
-
是的,我可以,一旦我创建了一个示例,我会告诉你!
-
嘿,通过在 angular 的 package.json 中添加“--host 0.0.0.0 --disableHostCheck true”解决了这个问题,所以现在命令是“start”:“ng serve --host 0.0 .0.0 --disableHostCheck true"
标签: angular mongodb express nginx docker-compose