我的申请正在运作。 console.log记录在日志中,并能够在cmd上显示process.env.URL。但是,在浏览器上,它返回错误502,错误的网关。
这是我的docker-compose
version: "2"
volumes:
mongostorage:
services:
app:
build: ./app
ports:
- "3000"
links:
- mongo
- redis
command: node ./bin/www
nginx:
build: ./nginx
ports:
- "80:80"
links:
- app:app
mongo:
image: mongo:latest
environment:
- MONGO_DATA_DIR=/data/db
volumes:
- mongostorage:/data/db
ports:
- "27017:27017"
redis:
image: redis
volumes:
- ./data/redis/db:/data/db
ports:
- "6379:6379"
nginx.conf
events {
worker_connections 1024;
}
http{
upstream app.dev{
least_conn;
server app:3000 weight=10 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name app.dev;
location / {
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
}
这是app / Dockerfile
FROM node:6.3
WORKDIR /var/www/app
RUN mkdir -p /var/www/app
COPY package.json /var/www/app
RUN npm install
COPY . /var/www/app
这是nginx / Dockerfile
FROM nginx:latest
EXPOSE 80
COPY nginx.conf /etc/nginx/nginx.conf
答案 0 :(得分:0)
在你的nginx.conf文件中,在proxy_pass_http中你应该使用服务器名称,即
proxy_pass http://app.dev/
代替proxy_pass http://app
,它应该有效;