chore(docker): 简化nginx docker的处理

This commit is contained in:
2025-12-24 14:10:34 +08:00
parent 80998fba70
commit dffb2563be
2 changed files with 5 additions and 32 deletions

View File

@@ -45,9 +45,7 @@ services:
- "com.docker.compose.project.working_dir=${PROJECT_NAME}_${APP_ENV}"
nginx:
build:
context: ./docker/nginx
dockerfile: Dockerfile
image: nginx:alpine
container_name: ${PROJECT_NAME}_${APP_ENV}_nginx
restart: always
ports:
@@ -58,6 +56,10 @@ services:
- ./src:/var/www/html:rw
# 更新下载源列表以加速apt-get
- ./docker/debian/sources.list:/etc/apt/sources.list:ro
# 挂载 nginx 配置文件
- ./docker/nginx/conf.c:/etc/nginx/conf.c:ro
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
- ./docker/nginx/sites-enabled:/etc/nginx/sites-enabled:ro
# 创建临时目录
- /var/www/server/nginx/proxy_temp_dir
- /var/www/server/nginx/proxy_cache_dir

View File

@@ -1,29 +0,0 @@
FROM nginx:alpine
# 删除默认配置
RUN rm /etc/nginx/conf.d/default.conf
#
# - ./.docker/nginx/conf.c:/etc/nginx/conf.c:ro
# - ./.docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
# - ./.docker/nginx/sites-enabled:/etc/nginx/sites-enabled:ro
# 将本地 nginx 配置复制到镜像中并设置为只读
COPY ./conf.c/ /etc/nginx/conf.c/
COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY ./sites-enabled/ /etc/nginx/sites-enabled/
# 设置只读权限(文件 0444目录及其内容 0555
RUN chmod 0444 /etc/nginx/conf.c \
&& chmod 0444 /etc/nginx/conf.d/default.conf \
&& chmod -R 0555 /etc/nginx/sites-enabled
# 设置工作目录
WORKDIR /var/www/html
# 创建日志目录
RUN mkdir -p /var/log/nginx
# 暴露端口
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]