将docker容器部署到heroku会产生:与特权相关的nginx错误

时间:2020-05-14 03:05:00

标签: docker nginx heroku

正如标题所述,将应用程序部署到Heroku并观察日志后出现的错误:

nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2

我的Dockerfile是:

#build stage
FROM node:14-alpine AS build
WORKDIR /usr/src/ssat-prep/client
ENV PATH /app/node_modules/.bin:$PATH
COPY . .
RUN yarn install --production && yarn build 

#run and serve stage
FROM nginx:alpine
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /usr/src/ssat-prep/client/build /usr/share/nginx/html
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]

我的nginx.conf:

server {

  listen 3000;

  location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    try_files $uri $uri/ /index.html;
  }

  error_page   500 502 503 504  /50x.html;

  location = /50x.html {
    root   /usr/share/nginx/html;
  }

}

请帮助我部署此应用程序

1 个答案:

答案 0 :(得分:0)

Heroku在环境变量PORT中为此提供了一个端口,而在Dockerfile中公开则不起作用。

#build stage
FROM node:14-alpine AS build
WORKDIR /usr/src/ssat-prep/client
ENV PATH /app/node_modules/.bin:$PATH
COPY . .
RUN yarn install --production && yarn build 

#run and serve stage
FROM nginx:alpine
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /usr/src/ssat-prep/client/build /usr/share/nginx/html

CMD ["nginx", "-g", "daemon off;"]
server {

  listen $PORT;

  location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    try_files $uri $uri/ /index.html;
  }

  error_page   500 502 503 504  /50x.html;

  location = /50x.html {
    root   /usr/share/nginx/html;
  }

}