这是我的 docker 文件
# stage1 - build react app first
FROM node:12.16.1-alpine3.9 as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY ./package.json /app/
COPY ./package-lock.json /app/
RUN npm i --silent
COPY . /app
RUN npm run build
# stage 2 - build the final image and copy the react build files
FROM nginx:1.17.8-alpine
COPY --from=build /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
COPY ServerCertificate.crt /etc/ssl/
COPY 2022pk.key /etc/ssl/
EXPOSE 443
CMD ["nginx", "-g", "daemon off;"]
这在 nginx.conf 文件中
server {
listen 443 ssl;
ssl_certificate /etc/ssl/ServerCertificate.crt;
ssl_certificate_key /etc/ssl/2022pk.key;
server_name *.com;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
# to redirect all the requests to index.html,
# useful when you are using react-router
try_files $uri /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
我收到错误
无法加载证书 "/root/etc/ssl/ServerCertificate.crt": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/root/etc/ssl /ServerCertificate.crt','r') 错误:2006D080:BIO 例程:BIO_new_file:没有这样的文件)
答案 0 :(得分:0)
在 Expose 中添加了 80 端口并且成功了!!