From 362979678643fc66f8a82f81c85e15c5708a1fbe Mon Sep 17 00:00:00 2001 From: sudoooooo Date: Mon, 20 May 2024 18:37:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20nginx=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 9 +++------ docker-run.sh | 2 ++ nginx/nginx.conf | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index ed7c8bd3..649ab2aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,18 +14,15 @@ RUN apt-get update && \ RUN npm config set registry https://registry.npmjs.org/ # 安装项目依赖 -RUN cd /xiaoju-survey/web && npm install && npm run build-only -# 用了后端服务代理启动,建议使用nginx启动 -#RUN cd /xiaoju-survey && cp -af ./web/dist/* ./server/public/ +RUN cd /xiaoju-survey/web && npm install && npm run build + # 覆盖nginx配置文件 COPY ./nginx/nginx.conf /etc/nginx/nginx.conf RUN cd /xiaoju-survey/server && npm install && npm run build # 暴露端口 需要跟nginx的port一致 -# EXPOSE 3000 -EXPOSE 8080 - +EXPOSE 80 # docker入口文件,启动nginx和运行pm2启动,并保证监听不断 CMD ["sh","docker-run.sh"] diff --git a/docker-run.sh b/docker-run.sh index 6fa554ad..838ce639 100644 --- a/docker-run.sh +++ b/docker-run.sh @@ -1,7 +1,9 @@ #! /bin/bash # 启动nginx +echo 'nginx start' nginx -g 'daemon on;' + # 启动后端服务 cd /xiaoju-survey/server npm run start:prod \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 73612e7e..88c6265d 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -18,9 +18,9 @@ http { sendfile on; keepalive_timeout 65; server { - listen 8080; + listen 80; # IPv6端口 - listen [::]:8080; + listen [::]:80; server_name localhost; # gzip config gzip on;