Google计算引擎上的Docker映像无法在端口80上运行

Google计算引擎上的Docker映像无法在端口80上运行,docker,nginx,google-cloud-platform,google-compute-engine,next.js,Docker,Nginx,Google Cloud Platform,Google Compute Engine,Next.js,我正在将我的Next.js/Nginx docker映像从容器注册表部署到计算引擎 一旦部署,应用程序将按预期运行,但它在端口3000而不是80上运行-即,我想在上访问它,但我只能在:3000上访问它。我在Nginx中设置了一个反向代理,将端口3000转发到80,但它似乎不起作用 当我运行docker compose up时,可以在localhost上访问该应用程序(而不是localhost:3000) Dockerfile FROM node:alpine as react-build RU

我正在将我的Next.js/Nginx docker映像从容器注册表部署到计算引擎

一旦部署,应用程序将按预期运行,但它在端口3000而不是80上运行-即,我想在
上访问它,但我只能在
:3000
上访问它。我在Nginx中设置了一个反向代理,将端口3000转发到80,但它似乎不起作用

当我运行
docker compose up
时,可以在
localhost
上访问该应用程序(而不是
localhost:3000

Dockerfile

FROM node:alpine as react-build

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
RUN npm install --global pm2

COPY . /usr/src/app
RUN npm run build
# EXPOSE 3000
EXPOSE 80

CMD [ "pm2-runtime", "start", "npm", "--", "start" ]
FROM nginx:alpine

# Remove any existing config files
RUN rm /etc/nginx/conf.d/*

# Copy config files
# *.conf files in "conf.d/" dir get included in main config
COPY ./default.conf /etc/nginx/conf.d/
docker compose.yml

version: '3'
services:
  nextjs: 
    build: ./
  nginx: 
    build: ./nginx
    ports:
      - 80:80
/nginx/Dockerfile

FROM node:alpine as react-build

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
RUN npm install --global pm2

COPY . /usr/src/app
RUN npm run build
# EXPOSE 3000
EXPOSE 80

CMD [ "pm2-runtime", "start", "npm", "--", "start" ]
FROM nginx:alpine

# Remove any existing config files
RUN rm /etc/nginx/conf.d/*

# Copy config files
# *.conf files in "conf.d/" dir get included in main config
COPY ./default.conf /etc/nginx/conf.d/
/nginx/default.conf

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;

server {
  listen 80;

  gzip on;
  gzip_proxied any;
  gzip_comp_level 4;
  gzip_types text/css application/javascript image/svg+xml;

  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;

  # BUILT ASSETS (E.G. JS BUNDLES)
  # Browser cache - max cache headers from Next.js as build id in url
  # Server cache - valid forever (cleared after cache "inactive" period)
  location /_next/static {
    #proxy_cache STATIC;
    proxy_pass http://localhost:3000;
  }

  # STATIC ASSETS (E.G. IMAGES)
  # Browser cache - "no-cache" headers from Next.js as no build id in url
  # Server cache - refresh regularly in case of changes
  location /static {
    #proxy_cache STATIC;
    proxy_ignore_headers Cache-Control;
    proxy_cache_valid 60m;
    proxy_pass http://locahost:3000;
  }

  # DYNAMIC ASSETS - NO CACHE
  location / {
    proxy_pass http://locahost:3000;
  }
}

你确定你的代理正确吗?应用程序dockerfile不应该公开3000和nginx代理它到80吗?看来你要暴露80岁了。这就是为什么你的应用程序可以在localhost而不是localhost:3000上访问。如果是这样的话,您的nginx代理将无法工作,因为它正在查看localhost:3000。因此,您的代理可能在某些地方配置错误,或者docker文件设置为在生产中以某种方式公开3000。您确定代理正确吗?应用程序dockerfile不应该公开3000和nginx代理它到80吗?看来你要暴露80岁了。这就是为什么你的应用程序可以在localhost而不是localhost:3000上访问。如果是这样的话,您的nginx代理将无法工作,因为它正在查看localhost:3000。因此,您的代理可能配置错误,或者docker文件设置为在生产中以某种方式公开3000。