问题描述
我正在尝试使用nginx作为docker容器中的代理服务器运行nuxtjs应用程序.所以,我有2个容器:nginx和nuxt
I'm trying to run nuxtjs application using nginx as proxy server in docker containers. So, I have 2 containers: nginx and nuxt
这是我构建nuxt应用程序的方式
here is how I'm building nuxt application
FROM node:11.15
ENV APP_ROOT /src
RUN mkdir ${APP_ROOT}
WORKDIR ${APP_ROOT}
ADD . ${APP_ROOT}
RUN npm install
RUN npm run build
ENV host 0.0.0.0
结果似乎很好
接下来是nginx配置
Next is nginx config
server {
listen 80;
server_name dev.iceik.com.ua;
location / {
proxy_pass http://nuxt:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
我也尝试过这种nginx配置
Also I've tried this nginx config
upstream nuxt {
server nuxt:3000;
}
server {
listen 80;
server_name dev.iceik.com.ua;
location / {
proxy_pass http://nuxt;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
最后是我的docker-compose文件
And finally my docker-compose file
version: "3"
services:
nuxt:
build: ./app/
container_name: nuxt
restart: always
ports:
- "3000:3000"
command:
"npm run start"
nginx:
image: nginx:1.17
container_name: nginx
ports:
- "80:80"
volumes:
- ./nginx:/etc/nginx/conf.d
depends_on:
- nuxt
我可以从Nginx容器ping Nuxt容器
I can ping nuxt container from nginx container
这里也是打开的端口
因此,预期结果是我可以访问我的nuxt应用程序.但是我收到502 Bad Gateway
So, the expected result is that I can access my nuxt application.However I'm getting 502 Bad Gateway
您有什么想法,为什么nginx不公开我的nuxt应用程序?
Do you have any ideas why nginx doesn't expose my nuxt application?
谢谢您的任何建议!
推荐答案
Nodejs被暴露为 localhost:3000
而不是 0.0.0.0:3000
Nodejs is exposed localhost:3000
instead of 0.0.0.0:3000
请更正它.会工作
这篇关于部署在Docker容器中的Nginx不会暴露部署在另一个Docker容器中的nuxtjs(502 Bad Gateway)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!