From 5e6ec0fa4c058cb9acdfd22b7c49273f67072d6c Mon Sep 17 00:00:00 2001 From: "Autumn.home" Date: Wed, 12 Jun 2024 20:40:02 +0800 Subject: [PATCH] add --- docker-compose.yml | 2 +- dockerfile | 37 +++++++++++++++++++++++++++++++++---- single-host-deployment.yml | 3 +-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f9b4eea..d851495 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: container_name: scope-sentry restart: always ports: - - "8082:8082" + - "8082:80" environment: TIMEZONE: Asia/Shanghai MONGODB_IP: 127.0.0.1 diff --git a/dockerfile b/dockerfile index 9044747..a565d82 100644 --- a/dockerfile +++ b/dockerfile @@ -1,18 +1,47 @@ FROM python:3.7-slim ENV TZ=Asia/Shanghai -RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \ - sed -i 's/security.debian.org/mirrors.aliyun.com\/debian-security/g' /etc/apt/sources.list RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +# 更新包列表并安装必要的包,包括 nginx RUN apt-get update && \ - apt-get install -y git curl ca-certificates libcurl4-openssl-dev && \ + apt-get install -y git curl ca-certificates libcurl4-openssl-dev nginx && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* +# 设置工作目录 WORKDIR /opt/ScopeSentry/ +# 复制 ScopeSentry 项目文件到工作目录 COPY ./ScopeSentry /opt/ScopeSentry/ +# 安装 Python 依赖包 RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir -CMD ["python", "main.py"] +# 移动 static 目录下的所有文件到 nginx 的默认根目录 +RUN cp -r /opt/ScopeSentry/static/* /var/www/html/ + +# 修改 Nginx 配置文件,添加反向代理规则 +RUN echo 'server {\n\ + listen 80;\n\ + server_name localhost;\n\ +\n\ + location / {\n\ + root /var/www/html;\n\ + try_files $uri $uri/ =404;\n\ + }\n\ +\n\ + location /api/ {\n\ + proxy_pass http://127.0.0.1:8082;\n\ + proxy_set_header Host $host;\n\ + proxy_set_header X-Real-IP $remote_addr;\n\ + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\ + proxy_set_header X-Forwarded-Proto $scheme;\n\ + }\n\ +}\n' > /etc/nginx/sites-available/default + +# 确保 Nginx 默认配置启用 +RUN ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/ + +# 启动 Nginx 和 Python 应用 +CMD service nginx start && python main.py diff --git a/single-host-deployment.yml b/single-host-deployment.yml index 99b72da..47a330c 100644 --- a/single-host-deployment.yml +++ b/single-host-deployment.yml @@ -2,7 +2,6 @@ version: "3.4" networks: scopesentry-network: - name: scopesentry-network driver: bridge services: @@ -45,7 +44,7 @@ services: - redis restart: always ports: - - "8082:8082" + - "8082:80" environment: TIMEZONE: Asia/Shanghai MONGODB_IP: scopesentry-mongodb