From 493392ed07a3c10ddc874040dbafc151e7223a4c Mon Sep 17 00:00:00 2001 From: jarvis2f <137974272+jarvis2f@users.noreply.github.com> Date: Mon, 17 Feb 2025 16:58:37 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Add=20support=20for=20dynam?= =?UTF-8?q?ic=20NGINX=20port=20configuration=20and=20update=20related=20fi?= =?UTF-8?q?les.(#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 8 ++++++++ Dockerfile | 7 ++++--- docker-compose.yaml | 1 + entrypoint.sh | 3 +++ nginx.conf => nginx.conf.template | 2 +- 5 files changed, 17 insertions(+), 4 deletions(-) rename nginx.conf => nginx.conf.template (97%) diff --git a/.env.example b/.env.example index d5aa4ec..70be479 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,14 @@ LOG_LEVEL=INFO APP_ENV=prod # The root directory of the application APP_ROOT=/app/data + +# PUID and PGID are the user id and group id of the user who owns the files in the mounted volume. +# PUID: 1000 +# PGID: 1000 + +# The port on which the nginx listens for incoming connections, default is 80 +# NGINX_PORT: 80 + # only use in test #TDLIB_PATH= #JAVA_HOME= diff --git a/Dockerfile b/Dockerfile index 8944580..a2ff9f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,11 +52,12 @@ WORKDIR /app ARG LIB_PATH=/app/tdlib ENV JAVA_HOME=/jre \ PATH="/jre/bin:$PATH" \ - LANG=C.UTF-8 + LANG=C.UTF-8 \ + NGINX_PORT=80 RUN npm install -g pm2 && \ apt-get update && \ - apt-get install -y --no-install-recommends nginx wget curl unzip tini gosu && \ + apt-get install -y --no-install-recommends nginx wget curl unzip tini gosu gettext && \ mkdir -p $LIB_PATH && \ wget --no-check-certificate -q -O libs.zip https://github.com/p-vorobyev/spring-boot-starter-telegram/releases/download/1.15.0/libs.zip && \ unzip -q libs.zip -d /tmp/tdlib && \ @@ -89,7 +90,7 @@ COPY --from=web-builder --chown=1000:1000 /web/.next/static /app/web/.next/stati COPY --chown=1000:1000 ./web/pm2.json /app/web/ COPY --chown=1000:1000 ./entrypoint.sh . -COPY --chown=1000:1000 ./nginx.conf /etc/nginx/nginx.conf +COPY --chown=1000:1000 ./nginx.conf.template /etc/nginx/nginx.conf.template EXPOSE 80 diff --git a/docker-compose.yaml b/docker-compose.yaml index ad6dc9d..2f3492f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,6 +13,7 @@ services: # PUID and PGID are the user id and group id of the user who owns the files in the mounted volume. # PUID: 1000 # PGID: 1000 + # NGINX_PORT: 80 APP_ENV: "prod" APP_ROOT: "/app/data" TELEGRAM_API_ID: ${TELEGRAM_API_ID} diff --git a/entrypoint.sh b/entrypoint.sh index a2f313e..597476f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -72,6 +72,9 @@ start_services() { # Set up signal handlers trap cleanup TERM INT +# Replace nginx.conf.template with environment variables +envsubst '$NGINX_PORT' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf + # Set up permissions setup_permissions diff --git a/nginx.conf b/nginx.conf.template similarity index 97% rename from nginx.conf rename to nginx.conf.template index 68fb8c8..84d727f 100644 --- a/nginx.conf +++ b/nginx.conf.template @@ -7,7 +7,7 @@ events { http { # 定义 server 块 server { - listen 80; + listen ${NGINX_PORT}; # 定义 WS 的代理规则 location /ws {