fix(docker): 修复nginx docker 问题
This commit is contained in:
@@ -45,7 +45,9 @@ services:
|
||||
- "com.docker.compose.project.working_dir=${PROJECT_NAME}_${APP_ENV}"
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
build:
|
||||
context: ./docker/nginx
|
||||
dockerfile: Dockerfile
|
||||
container_name: ${PROJECT_NAME}_${APP_ENV}_nginx
|
||||
restart: always
|
||||
ports:
|
||||
@@ -56,10 +58,6 @@ 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
|
||||
|
||||
21
docker/nginx/Dockerfile
Normal file
21
docker/nginx/Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
||||
FROM nginx:alpine
|
||||
|
||||
# 删除默认配置
|
||||
RUN rm /etc/nginx/conf.d/default.conf
|
||||
|
||||
|
||||
# 将本地 nginx 配置复制到镜像中
|
||||
COPY ./conf.c/ /etc/nginx/conf.c/
|
||||
COPY ./default.conf /etc/nginx/conf.d/default.conf
|
||||
COPY ./sites-enabled/ /etc/nginx/sites-enabled/
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 80 443
|
||||
|
||||
# 添加在Dockerfile末尾,CMD命令之前
|
||||
COPY ./entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
|
||||
# 启动nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
18
docker/nginx/entrypoint.sh
Normal file
18
docker/nginx/entrypoint.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "=== NGINX Docker 权限初始化 ==="
|
||||
|
||||
# 设置权限
|
||||
chmod -R 0444 /etc/nginx/conf.c
|
||||
chmod 0444 /etc/nginx/conf.d/default.conf
|
||||
chmod -R 0755 /etc/nginx/sites-enabled
|
||||
|
||||
|
||||
# 创建日志目录
|
||||
mkdir -p /var/log/nginx
|
||||
|
||||
echo "=== NGINX Docker 权限初始化完成 ==="
|
||||
|
||||
# 执行原有的启动命令
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user