dockerfile
FROM node:18.19.0 as build-stage
WORKDIR /nest-backend-ui
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# 基于nginx官方镜像
FROM nginx:stable-alpine as production-stage
# 从构建阶段复制构建结果到nginx服务器根目录
COPY --from=build-stage /nest-backend-ui/dist /usr/share/nginx/html
# 暴露80端口
EXPOSE 80
# 启动nginx,并且nginx将持续运行
CMD ["nginx", "-g", "daemon off;"]
此时访问接口报404或者502的往下看
查看宿主机ip地址
vi /etc/nginx/conf.d/default.conf 修改配置文件,加入nginx代理配置
location /api/
{
rewrite ^.+api/?(.*)$ /$1 break;
proxy_pass http://192.168.100.102:3000/;
}
修改完之后重启容器,重新请求已经数据已经成功请求回来了