From b170196996d9691932c2888a10f229f4bd778b9b Mon Sep 17 00:00:00 2001 From: chenjiale Date: Thu, 4 Dec 2025 09:29:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20Docker=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=B7=BB=E5=8A=A0=20Nginx=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E6=98=A0?= =?UTF-8?q?=E5=B0=84=EF=BC=8C=E4=BC=98=E5=8C=96=20Nginx=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 4 ++- scripts/Dockerfile | 6 +++- scripts/nginx.conf | 74 ++++++++++++++++++---------------------------- 3 files changed, 37 insertions(+), 47 deletions(-) diff --git a/.drone.yml b/.drone.yml index afb1372..220edc2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -27,9 +27,11 @@ steps: - name: dockersock path: /var/run/docker.sock commands: + - mkdir -p /opt/alert-front/conf + - cp scripts/nginx.conf /opt/alert-front/conf/default.conf - docker stop alert-front || true - docker rm alert-front || true - - docker run -d --restart always --name alert-front --network alert-net -p 5000:5000 alert-front:latest + - docker run -d --restart always --name alert-front --network alert-net -p 5000:5000 -v /opt/alert-front/conf:/etc/nginx/conf.d:ro alert-front:latest volumes: - name: dockersock diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 3ab1d0f..a0dc1d6 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -23,11 +23,15 @@ FROM nginx:stable-alpine AS production # 支持 .mjs 类型 RUN echo "types { application/javascript js mjs; }" > /etc/nginx/conf.d/mjs.conf +RUN rm -f /etc/nginx/conf.d/default.conf + # 拷贝构建产物 COPY --from=builder /app/dist /usr/share/nginx/html # 拷贝 nginx 配置 -COPY --from=builder /app/scripts/nginx.conf /etc/nginx/nginx.conf +COPY --from=builder /app/scripts/nginx.conf /etc/nginx/conf.d/default.conf + +VOLUME ["/etc/nginx/conf.d"] EXPOSE 5000 CMD ["nginx", "-g", "daemon off;"] diff --git a/scripts/nginx.conf b/scripts/nginx.conf index 5b9ae35..cbe1c3a 100644 --- a/scripts/nginx.conf +++ b/scripts/nginx.conf @@ -1,51 +1,35 @@ -worker_processes 1; - -events { - worker_connections 1024; -} - -http { - include mime.types; - default_type application/octet-stream; - - sendfile on; - - server { - listen 5000; - server_name _; - client_max_body_size 20M; - - # 静态资源和前端页面 - location / { - root /usr/share/nginx/html; - try_files $uri $uri/ /index.html; - index index.html; - - # CORS - add_header 'Access-Control-Allow-Origin' '*'; - add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; - add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; - if ($request_method = 'OPTIONS') { - add_header 'Access-Control-Max-Age' 1728000; - add_header 'Content-Type' 'text/plain charset=UTF-8'; - add_header 'Content-Length' 0; - return 204; - } +server { + listen 5000; + server_name _; + client_max_body_size 20M; + + location / { + root /usr/share/nginx/html; + try_files $uri $uri/ /index.html; + index index.html; + + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; } + } - # 代理 API 请求到后端容器 - location /admin-api/ { - proxy_pass http://alert-backend:48080; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } + location /admin-api/ { + proxy_pass http://alert-backend:48080; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } - error_page 500 502 503 504 /50x.html; + error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } + location = /50x.html { + root /usr/share/nginx/html; } } From 2821b0faa8e187a3dab12c5e5eebbe955fce9332 Mon Sep 17 00:00:00 2001 From: chenjiale Date: Thu, 4 Dec 2025 09:36:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20Docker=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E4=BF=AE=E6=AD=A3=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E4=BB=A5=E7=A1=AE=E4=BF=9D=E5=89=8D=E7=AB=AF=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 220edc2..9477fe3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,14 +26,19 @@ steps: volumes: - name: dockersock path: /var/run/docker.sock + - name: front-conf + path: /opy/alert/alert-front/conf commands: - - mkdir -p /opt/alert-front/conf - - cp scripts/nginx.conf /opt/alert-front/conf/default.conf + - mkdir -p /opy/alert/alert-front/conf + - cp scripts/nginx.conf /opy/alert/alert-front/conf/default.conf - docker stop alert-front || true - docker rm alert-front || true - - docker run -d --restart always --name alert-front --network alert-net -p 5000:5000 -v /opt/alert-front/conf:/etc/nginx/conf.d:ro alert-front:latest + - docker run -d --restart always --name alert-front --network alert-net -p 5000:5000 -v /opy/alert/alert-front/conf:/etc/nginx/conf.d:ro alert-front:latest volumes: - name: dockersock host: path: /var/run/docker.sock + - name: front-conf + host: + path: /opy/alert/alert-front/conf From 97c2cb89de55ce537e7eba3aa16d9f578d7de6ba Mon Sep 17 00:00:00 2001 From: chenjiale Date: Thu, 4 Dec 2025 09:42:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=AE=B9=E5=99=A8=E6=AD=A3=E7=A1=AE=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index 9477fe3..134d45c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -27,13 +27,13 @@ steps: - name: dockersock path: /var/run/docker.sock - name: front-conf - path: /opy/alert/alert-front/conf + path: /opt/alert/alert-front/conf commands: - - mkdir -p /opy/alert/alert-front/conf - - cp scripts/nginx.conf /opy/alert/alert-front/conf/default.conf + - mkdir -p /opt/alert/alert-front/conf + - cp scripts/nginx.conf /opt/alert/alert-front/conf/default.conf - docker stop alert-front || true - docker rm alert-front || true - - docker run -d --restart always --name alert-front --network alert-net -p 5000:5000 -v /opy/alert/alert-front/conf:/etc/nginx/conf.d:ro alert-front:latest + - docker run -d --restart always --name alert-front --network alert-net -p 5000:5000 -v /opt/alert/alert-front/conf:/etc/nginx/conf.d:ro alert-front:latest volumes: - name: dockersock @@ -41,4 +41,4 @@ volumes: path: /var/run/docker.sock - name: front-conf host: - path: /opy/alert/alert-front/conf + path: /opt/alert/alert-front/conf