Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2983477b7a | |||
| 105fb9f9cf | |||
| 7df1a4796f | |||
| 694480f2ae | |||
| e8d70fcef1 | |||
| 9501cca4cf | |||
| 8be9d96b27 | |||
| b773351c0c | |||
| e6d4313367 | |||
| 8a7347671e | |||
| 04bdfafabb | |||
| b55f06f662 | |||
| c8a03964a6 | |||
| a4b156778e | |||
| aae5948220 | |||
| 8dd6b61d4d | |||
| 245d253961 | |||
| 22e345f0cd | |||
| 6799a1c1f8 | |||
| d85fdc6f81 | |||
| d628ecda82 | |||
| be8360e035 | |||
| 1be30da4b9 | |||
| 268a113d77 | |||
| a40a27b702 | |||
| 5eae66198b | |||
| f2784d8661 |
Submodule
+1
Submodule .ci/common added at b0ca0dc3a3
@@ -0,0 +1,57 @@
|
||||
# 忽略所有 .git 相关
|
||||
.git
|
||||
.gitignore
|
||||
.gitmodules
|
||||
.gitattributes
|
||||
|
||||
# 忽略 IDE 和编辑器文件
|
||||
.idea/
|
||||
.vscode/
|
||||
*.iml
|
||||
Thumbs.db
|
||||
|
||||
# 忽略本地依赖和构建缓存
|
||||
node_modules/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.env
|
||||
.env.*
|
||||
secrets/
|
||||
config/local.*
|
||||
|
||||
# 忽略日志和临时文件
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# 忽略测试报告(除非需要)
|
||||
coverage/
|
||||
htmlcov/
|
||||
.pytest_cache/
|
||||
|
||||
# 忽略 macOS 特有文件
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
Icon?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
# 忽略构建产物(如果 Docker 内部会重新构建)
|
||||
dist/
|
||||
build/
|
||||
out/
|
||||
target/
|
||||
|
||||
# 忽略项目特有文件及目录
|
||||
img
|
||||
build.sh
|
||||
LICENSE
|
||||
README.md
|
||||
*.yml
|
||||
*.yaml
|
||||
|
||||
# 忽略 AI 规则文件
|
||||
.lingma
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
|
||||
Icon\r\r
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule ".ci/common"]
|
||||
path = .ci/common
|
||||
url = https://git.colovu.com/docker/common.git
|
||||
@@ -0,0 +1,55 @@
|
||||
# 注意:
|
||||
# 1. git commit 信息中包含"[CI SKIP]"或"[SKIP CI]"则不触发工作流(注意大小写)
|
||||
# 2. 工作步骤中包含 volumes 挂载时,需在 Woodpecker 配置中添加 volumes 挂载信任(Trust)
|
||||
# 3. lables 配置项,可配置多个;如果存在,则必须完全符合 Runner 创建时设置的 Lables 配置项
|
||||
# 4. command 中,引用自定义变量不能使用`${VAR}`方式,需要使用`$VAR`方式;带花括号的变量,会在 Woodpecker 模板引擎解析阶段被替换(此时变量为空)
|
||||
# 5. 多架构编译后推送至 SWR 报错,或单架构编译后必须在推送时明确指定架构信息才能推送;可通过在编译命令中增加参数`--provenance=false --sbom=false`解决
|
||||
# 6. 使用 Git Submodule 管理通用脚本时,需手动更新 Submodule
|
||||
|
||||
when:
|
||||
# 匹配 main
|
||||
- event: push
|
||||
branch: main
|
||||
# 匹配 master
|
||||
- event: push
|
||||
branch: master
|
||||
# 匹配数字开头的分支,如 1.0, 2, 3.2.1
|
||||
- event: push
|
||||
branch: "[0-9]*"
|
||||
# 匹配 v 开头的版本分支,如 v1, v2.0
|
||||
- event: push
|
||||
branch: "v[0-9]*"
|
||||
# 匹配 tag 事件
|
||||
- event: tag
|
||||
ref: "refs/tags/(v?[0-9].*)"
|
||||
|
||||
labels:
|
||||
runtime: docker
|
||||
arch: amd64
|
||||
multiarch: "true"
|
||||
|
||||
steps:
|
||||
- name: 初始化子模块
|
||||
image: alpine/git
|
||||
commands:
|
||||
- git submodule update --init --recursive
|
||||
|
||||
- name: 编译并推送镜像
|
||||
image: docker:cli
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
environment:
|
||||
SWR_REGISTRY: "swr.cn-north-4.myhuaweicloud.com"
|
||||
DOCKER_CLI_EXPERIMENTAL: enabled
|
||||
SWR_USERNAME:
|
||||
from_secret: swr_colovu_user
|
||||
SWR_PASSWORD:
|
||||
from_secret: swr_colovu_passwd
|
||||
commands:
|
||||
- |
|
||||
# 直接执行 Submodule .ci/common 下的构建推送脚本
|
||||
if [ ! -f ".ci/common/build_push.sh" ]; then
|
||||
echo "错误: 未找到 .ci/common/build_push.sh 脚本"
|
||||
exit 1
|
||||
fi
|
||||
- sh ./.ci/common/build_push.sh
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
# Ver: 1.12 by Endial Fang (endial@126.com)
|
||||
#
|
||||
|
||||
# 系统默认变量 ====================================================================
|
||||
# 该部分变量为系统根据编译命令默认设置
|
||||
# `TARGETPLATFORM`:构建后的目标平台信息。如 `linux/amd64`,`linux/arm/v7`,`windows/amd64`
|
||||
# `TARGETOS`:目标平台信息(TARGETPLATFORM)中的操作系统部分,如:`linux`、`windows`
|
||||
# `TARGETARCH`:目标平台信息(TARGETPLATFORM)中的平台架构部分,如:`amd64`、`arm`
|
||||
# `TARGETVARIANT`:目标平台信息(TARGETPLATFORM)中的版本变体部分,如:`v7`
|
||||
# `BUILDPLATFORM`:用于构建的节点平台信息
|
||||
# `BUILDOS`:用于构建的节点平台信息(BUILDPLATFORM)中的操作系统部分
|
||||
# `BUILDARCH`:用于构建的节点平台信息(BUILDPLATFORM)中的平台架构部分
|
||||
# `BUILDVARIANT`:用于构建的节点平台信息(BUILDPLATFORM)中的版本变体部分
|
||||
|
||||
# 可变参数 ========================================================================
|
||||
# 该部分变量,在编译命令中通过 `--build-arg` 传入;如果未设置,则使用下面对应的默认值
|
||||
# 依赖镜像下载地址: docker.io (默认) / swr.cn-north-4.myhuaweicloud.com/colovu/
|
||||
# apt源: default / aliyun / ustc
|
||||
# 软件包本地服务器: http://pkgs.colovu.com/dist
|
||||
|
||||
ARG APP_NAME=nginx
|
||||
ARG APP_VER=1.29.4
|
||||
ARG REGISTRY_URL="swr.cn-north-4.myhuaweicloud.com/colovu/"
|
||||
ARG APT_SOURCE=aliyun
|
||||
ARG LOCAL_URL=""
|
||||
|
||||
# 0. 预处理 ======================================================================
|
||||
FROM ${REGISTRY_URL}debian-builder:v13 AS builder
|
||||
|
||||
# 声明需要使用的全局可变参数
|
||||
ARG APP_NAME
|
||||
ARG APP_VER
|
||||
ARG APT_SOURCE
|
||||
ARG LOCAL_URL
|
||||
ARG TARGETARCH
|
||||
|
||||
# 选择软件包源,加速后续软件包安装
|
||||
RUN /usr/local/sbin/select_source ${APT_SOURCE};
|
||||
|
||||
# 安装依赖的软件包及库
|
||||
RUN /usr/local/sbin/install_pkg libperl-dev \
|
||||
libpcre2-32-0 libpcre2-16-0 libpcre2-posix3 libpcre2-dev \
|
||||
zlib1g zlib1g-dev \
|
||||
libxslt1.1 libxslt1-dev \
|
||||
libgd3 libgd-dev \
|
||||
libxml2 libxml2-dev \
|
||||
geoip-bin geoip-database libgeoip-dev
|
||||
|
||||
# 下载并解压软件包 nginx: https://nginx.org/download/nginx-1.29.4.tar.gz
|
||||
RUN set -eux; \
|
||||
appName="${APP_NAME}-${APP_VER}.tar.gz"; \
|
||||
[ -n ${LOCAL_URL} ] && localURL=${LOCAL_URL}/${APP_NAME}; \
|
||||
appUrls="${localURL:-} \
|
||||
http://nginx.org/download \
|
||||
"; \
|
||||
/usr/local/sbin/download_pkg unpack ${appName} "${appUrls}";
|
||||
|
||||
# 源码编译: 编译后将配置文件模板拷贝至 /usr/local/${app_name}/share/${app_name} 中
|
||||
RUN set -eux; \
|
||||
APP_ARCH=${TARGETARCH:-$(dpkg --print-architecture)}; \
|
||||
APP_SRC="/tmp/${APP_NAME}-${APP_VER}"; \
|
||||
cd ${APP_SRC}; \
|
||||
LDFLAGS="-L/usr/local/lib -L/usr/lib/${APP_ARCH}-linux-gnu" \
|
||||
./configure \
|
||||
--prefix=/usr/local/${APP_NAME} \
|
||||
--sbin-path=/usr/local/${APP_NAME}/sbin/nginx \
|
||||
--conf-path=/usr/local/${APP_NAME}/etc/nginx/nginx.conf \
|
||||
--pid-path=/var/run/${APP_NAME}/nginx.pid \
|
||||
--lock-path=/var/run/${APP_NAME}/nginx.lock \
|
||||
--http-log-path=/var/log/${APP_NAME}/access.log \
|
||||
--error-log-path=/var/log/${APP_NAME}/error.log \
|
||||
--modules-path=/usr/local/${APP_NAME}/modules \
|
||||
--http-client-body-temp-path=/var/cache/${APP_NAME}/client_temp \
|
||||
--http-proxy-temp-path=/var/cache/${APP_NAME}/proxy_temp \
|
||||
--http-fastcgi-temp-path=/var/cache/${APP_NAME}/fastcgi_temp \
|
||||
--http-uwsgi-temp-path=/var/cache/${APP_NAME}/uwsgi_temp \
|
||||
--http-scgi-temp-path=/var/cache/${APP_NAME}/scgi_temp \
|
||||
\
|
||||
--with-http_ssl_module \
|
||||
--with-http_v2_module \
|
||||
--with-http_v3_module \
|
||||
--with-http_realip_module \
|
||||
--with-http_geoip_module \
|
||||
--with-http_sub_module \
|
||||
--with-http_dav_module \
|
||||
--with-http_mp4_module \
|
||||
--with-http_flv_module \
|
||||
--with-http_gunzip_module \
|
||||
--with-http_gzip_static_module \
|
||||
--with-http_auth_request_module \
|
||||
--with-http_addition_module \
|
||||
--with-http_slice_module \
|
||||
--with-http_random_index_module \
|
||||
--with-http_secure_link_module \
|
||||
--with-http_stub_status_module \
|
||||
--with-mail_ssl_module \
|
||||
--with-pcre \
|
||||
--with-pcre-jit \
|
||||
--with-poll_module \
|
||||
--with-stream_realip_module \
|
||||
--with-stream_ssl_module \
|
||||
--with-threads \
|
||||
\
|
||||
--with-stream=dynamic \
|
||||
--with-stream_geoip_module=dynamic \
|
||||
--with-http_perl_module=dynamic \
|
||||
--with-http_geoip_module=dynamic \
|
||||
--with-http_xslt_module=dynamic \
|
||||
--with-http_image_filter_module=dynamic \
|
||||
--with-mail=dynamic \
|
||||
; \
|
||||
make -j "$(nproc)" && make install; \
|
||||
strip /usr/local/${APP_NAME}/sbin/nginx;
|
||||
|
||||
# 生成默认 PHP 首页文件
|
||||
RUN set -eux; \
|
||||
echo "<?php" >/usr/local/${APP_NAME}/html/index.php; \
|
||||
echo "phpinfo();" >>/usr/local/${APP_NAME}/html/index.php; \
|
||||
echo "?>" >>/usr/local/${APP_NAME}/html/index.php;
|
||||
|
||||
# 检测并生成依赖文件记录
|
||||
RUN set -eux; \
|
||||
find /usr/local/${APP_NAME} -type f -executable -exec ldd '{}' ';' | \
|
||||
awk '/=>/ { print $(NF-1) }' | xargs -r basename -a | sort -u | \
|
||||
xargs -r dpkg-query --search 2>/dev/null | cut -d: -f1 | sort -u \
|
||||
>>/usr/local/${APP_NAME}/runDeps;
|
||||
|
||||
# 1. 生成镜像 =====================================================================
|
||||
FROM ${REGISTRY_URL}debian:v13
|
||||
|
||||
# 声明需要使用的全局可变参数(ARG声明的变量仅编译打包阶段有效)
|
||||
ARG APP_NAME
|
||||
ARG APP_VER
|
||||
ARG APT_SOURCE
|
||||
|
||||
# 定义应用的基础信息变量(ENV声明的变量实例化后容器内有效)
|
||||
ENV APP_NAME=${APP_NAME} \
|
||||
APP_VER=${APP_VER} \
|
||||
APP_EXEC=${APP_NAME} \
|
||||
APP_USER=${APP_NAME} \
|
||||
\
|
||||
PATH="${PATH}:/usr/local/${APP_NAME}/sbin"
|
||||
|
||||
# 镜像元数据标签 - 符合OCI镜像规范
|
||||
LABEL org.opencontainers.image.title="${APP_NAME}" \
|
||||
org.opencontainers.image.version="${APP_VER}" \
|
||||
org.opencontainers.image.description="Docker image for Nginx." \
|
||||
org.opencontainers.image.authors="Endial Fang <endial@126.com>" \
|
||||
org.opencontainers.image.url="https://gitee.com/colovu/docker-${APP_NAME}" \
|
||||
org.opencontainers.image.vendor="Endial Fang (colovu)" \
|
||||
org.opencontainers.image.licenses="Apache-2.0" \
|
||||
org.opencontainers.image.source="https://gitee.com/colovu/docker-${APP_NAME}" \
|
||||
org.opencontainers.image.documentation="https://gitee.com/colovu/docker-${APP_NAME}/blob/main/README.md" \
|
||||
maintainer="Endial Fang <endial@126.com>"
|
||||
|
||||
# 拷贝多阶段构建结果输出及客制化脚本
|
||||
COPY --from=builder /usr/local/${APP_NAME} /usr/local/${APP_NAME}
|
||||
COPY customer /
|
||||
|
||||
RUN set -eux; \
|
||||
\
|
||||
useradd -U -u 996 -d /srv/${APP_NAME} -s /usr/sbin/nologin -r ${APP_USER}; \
|
||||
mkdir -p /var/log/${APP_NAME} /var/run/${APP_NAME} /var/cache/${APP_NAME}; \
|
||||
mkdir -p /srv/${APP_NAME}/conf /srv/${APP_NAME}/data /srv/${APP_NAME}/cert /srv/${APP_NAME}/log; \
|
||||
chown -R ${APP_USER}:${APP_USER} /var/log/${APP_NAME} /var/run/${APP_NAME} /var/cache/${APP_NAME}; \
|
||||
chown -R ${APP_USER}:${APP_USER} /usr/local/${APP_NAME} /srv/${APP_NAME}; \
|
||||
\
|
||||
/bin/bash -c "ln -sf /usr/local/${APP_NAME}/etc/${APP_NAME} /etc/"; \
|
||||
\
|
||||
/usr/local/sbin/select_source ${APT_SOURCE}; \
|
||||
\
|
||||
/usr/local/sbin/install_pkg `cat /usr/local/${APP_NAME}/runDeps`; \
|
||||
\
|
||||
overrideShell="/usr/local/overrides/overrides-${APP_VER}.sh"; \
|
||||
[ -e "${overrideShell}" ] && /bin/bash "${overrideShell}"; \
|
||||
\
|
||||
${APP_EXEC} -V ;
|
||||
|
||||
# 配置容器的数据卷、工作目录及服务端口(必须保证端口在1024之上)
|
||||
VOLUME ["/srv/${APP_NAME}/conf", "/srv/${APP_NAME}/data", "/srv/${APP_NAME}/cert", "/srv/${APP_NAME}/log"]
|
||||
WORKDIR /srv/${APP_NAME}
|
||||
EXPOSE 8080 8443
|
||||
|
||||
#HEALTHCHECK NONE
|
||||
HEALTHCHECK --interval=30s --timeout=30s --retries=3 CMD curl -fs http://localhost:8080/ || exit 1
|
||||
#HEALTHCHECK --interval=10s --timeout=10s --retries=3 CMD netstat -ltun | grep 8080
|
||||
|
||||
# 使用 dumb-init 启动入口 Shell,确保容器可以接收控制信号;并使用前台方式启动应用程序
|
||||
ENTRYPOINT ["dumb-init", "entry.sh"]
|
||||
CMD ["run.sh"]
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Endial Fang (endial@126.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,3 +1,167 @@
|
||||
# Nginx
|
||||
|
||||
停止维护 v1.24 版本.
|
||||
针对 [Nginx](http://nginx.org) 应用的 Docker 镜像,用于提供 Nginx 服务。容器详细使用说明可参考仓库:[Gitee](https://www.gitee.com/endial/studylife.git) 或 [Github](https://www.github.com/endial/studylife.git)中`服务器运维`相应文档。
|
||||
|
||||
使用说明可参照:[官方说明](http://nginx.org/en/docs/)
|
||||
|
||||

|
||||
|
||||
**版本信息:**
|
||||
|
||||
- 1.29、latest
|
||||
- 1.28
|
||||
|
||||
**镜像信息:**
|
||||
|
||||
* 镜像地址:
|
||||
- 阿里云: registry.cn-shenzhen.aliyuncs.com/colovu/nginx:latest
|
||||
- Colovu Registry: docker.colovu.com/colovu/nginx:latest
|
||||
- 依赖镜像:colovu/debian:12
|
||||
|
||||
> 后续相关命令行默认使用 Aliyun ACR 镜像服务器做说明
|
||||
|
||||
## TL;DR
|
||||
|
||||
Docker 快速启动命令:
|
||||
|
||||
```shell
|
||||
# 从 Registry 服务器下载镜像并启动
|
||||
$ docker run -d -p 80:8080 registry.cn-shenzhen.aliyuncs.com/colovu/nginx:latest
|
||||
```
|
||||
|
||||
- `registry.cn-shenzhen.aliyuncs.com/colovu/imgname:<TAG>`:镜像名称及版本标签 TAG;标签不指定时默认使用最新版本
|
||||
|
||||
启动后,可以使用浏览器访问:`http://localhost/`,出现默认的 Nginx 首页。
|
||||
|
||||
Docker-Compose 快速启动命令:
|
||||
|
||||
```shell
|
||||
# 从 Gitee 下载 Compose 文件
|
||||
$ curl -sSL -o https://gitee.com/colovu/docker-nginx/raw/master/docker-compose.yml
|
||||
|
||||
# 从 Github 下载 Compose 文件
|
||||
$ curl -sSL -o https://raw.githubusercontent.com/colovu/docker-nginx/master/docker-compose.yml
|
||||
|
||||
# 创建并启动容器
|
||||
$ docker-compose up -d
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 默认对外声明
|
||||
|
||||
### 端口
|
||||
|
||||
- 8080:HTTP 端口
|
||||
- 8443:HTTPS 端口
|
||||
|
||||
### 数据卷
|
||||
|
||||
镜像默认提供以下数据卷定义,默认数据分别存储在自动生成的应用名对应`nginx`子目录中:
|
||||
|
||||
```shell
|
||||
/srv/nginx/conf # 配置文件
|
||||
/srv/nginx/data # 数据文件,主要存放应用数据
|
||||
/srv/nginx/cert # 证书文件存放目录
|
||||
/srv/nginx/log # 日志文件
|
||||
/var/run/nginx # 进程运行PID文件
|
||||
```
|
||||
|
||||
如果需要持久化存储相应数据,需要**在宿主机建立本地目录**,并在使用镜像初始化容器时进行映射。宿主机相关的目录中如果不存在对应应用`nginx`的子目录或相应数据文件,则容器会在初始化时创建相应目录及文件。
|
||||
|
||||
## 容器配置
|
||||
|
||||
在初始化 `Nginx` 容器时,如果没有预置配置文件,可以在命令行中设置相应环境变量对默认参数进行修改。类似命令如下(配置环境变量`APP_ENV_KEY_NAME`的值为`key_value`):
|
||||
|
||||
```shell
|
||||
$ docker run -d -e "APP_ENV_KEY_NAME=key_value" registry.cn-shenzhen.aliyuncs.com/colovu/nginx:latest
|
||||
```
|
||||
|
||||
### 自动变量替换
|
||||
|
||||
针对应用配置文件中的配置项,支持由环境变量名自动替换生成,该类环境变量需要使用统一前缀,定义规则为:`APP_CFG_*=<val>`
|
||||
|
||||
- `APP_CFG_`:环境变量自动替换标识,具备该前缀的环境变量会被自动处理并更新至配置文件
|
||||
- `*`:配置文件中对应的配置项名,大小写需要符合实际参数名要求;特殊字符需要符合`特殊字符替换规则`
|
||||
- `<val>`:配置项对应值
|
||||
|
||||
**特殊字符替换规则**:
|
||||
|
||||
因为 Shell 变量只能以字母、数字和下划线组成,针对'xml'、'ini'等配置文件中使用的'.'、'-'等特殊字符,需要进行重定义及转换。预定义如下:
|
||||
|
||||
+ `_` ==> `_` : 应用配置属性中的`_`(下划线),与环境变量相同
|
||||
+ `__` ==> `.` : 应用配置属性中的`.`(半角点),在环境变量中由`__`(双下划线)表示
|
||||
+ `___` ==> `-` : 应用配置属性中的`-`(中划线),在环境变量中由`___`(三下划线)表示
|
||||
|
||||
例如:
|
||||
|
||||
```shell
|
||||
# 常用于`key-value`类型的配置
|
||||
APP_CFG_min_wal_size=100MB
|
||||
APP_CFG_max_wal_size="400MB"
|
||||
|
||||
# 容器启动后,应用配置文件中对应配置项生效,且设置为相应值:
|
||||
min_wal_size = '100MB'
|
||||
max_wal_size = '400MB'
|
||||
|
||||
|
||||
# 常用于`xml`类型的配置
|
||||
APP_CFG_fs__defaultFS=hdfs://namenode:8020
|
||||
APP_CFG_yarn__log___aggregation___enable=true
|
||||
|
||||
# 容器启动后,应用配置文件中对应配置项生效,且设置为相应值:
|
||||
<property><name>fs.defaultFS</name><value>hdfs://namenode:8020</value></property>
|
||||
<property><name>yarn.log-aggregation-enable</name><value>true</value></property>
|
||||
```
|
||||
|
||||
### 常规配置参数
|
||||
|
||||
常规配置参数用来配置容器基本属性,一般情况下需要设置,主要包括:
|
||||
|
||||
-
|
||||
|
||||
### 常规可选参数
|
||||
|
||||
如果没有必要,可选配置参数可以不用定义,直接使用对应的默认值,主要包括:
|
||||
|
||||
- `ENV_DEBUG`:默认值:**false**。设置是否输出容器调试信息。可选值:false、no、true、yes
|
||||
- `ALLOW_ANONYMOUS`:默认值:**no**。设置是否允许匿名链接。可选值:false、no、true、yes
|
||||
|
||||
### 集群配置参数
|
||||
|
||||
配置服务为集群工作模式时,通过以下参数进行配置:
|
||||
|
||||
-
|
||||
|
||||
### TLS配置参数
|
||||
|
||||
配置服务使用 TLS 加密时,通过以下参数进行配置:
|
||||
|
||||
-
|
||||
|
||||
## 安全
|
||||
|
||||
### 容器安全
|
||||
|
||||
本容器默认使用`non-root`运行应用,以加强容器的安全性。在使用`non-root`用户运行容器时,相关的资源访问会受限;应用仅能操作镜像创建时指定的路径及数据。使用`non-root`方式的容器,更适合在生产环境中使用。
|
||||
|
||||
如果需要赋予容器内应用访问外部设备的权限,可以使用以下两种方式:
|
||||
|
||||
- 启动参数增加`--privileged=true`选项
|
||||
- 针对特定权限需要使用`--cap-add`单独增加特定赋权,如:ALL、NET_ADMIN、NET_RAW
|
||||
|
||||
如果需要切换为`root`方式运行应用,可以在启动命令中增加`-u root`以指定运行的用户。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 容器中应用的启动参数不能配置为后台运行,如果应用使用后台方式运行,则容器的启动命令会在运行后自动退出,从而导致容器退出
|
||||
|
||||
## 更新记录
|
||||
|
||||
- 2026/1/21: 更新版本为 v1.29.3
|
||||
- 2023/8/3: 更新为 Nginx 1.24.0
|
||||
|
||||
----
|
||||
|
||||
本文原始来源 [Endial Fang](https://github.com/colovu) @ [Github.com](https://github.com)
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
1.28.1
|
||||
1.29.4
|
||||
|
||||
|
||||
Dynamic Modules
|
||||
Main nginx package is built with all modules that do not require additional libraries to avoid extra dependencies. Since version 1.9.11, nginx supports dynamic modules and the following modules are built as dynamic and shipped as separate packages:
|
||||
nginx-module-geoip
|
||||
nginx-module-image-filter
|
||||
nginx-module-njs
|
||||
nginx-module-perl
|
||||
nginx-module-xslt
|
||||
Additionally, since version 1.25.3, the following module is shipped as a separate package:
|
||||
nginx-module-otel
|
||||
Additionally, since version 1.29.1, the following module is shipped as a separate package:
|
||||
nginx-module-acme
|
||||
|
||||
原始 nginx.conf:
|
||||
|
||||
#user nobody;
|
||||
worker_processes 1;
|
||||
|
||||
#error_log logs/error.log;
|
||||
#error_log logs/error.log notice;
|
||||
#error_log logs/error.log info;
|
||||
|
||||
#pid logs/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
#access_log logs/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
#access_log logs/host.access.log main;
|
||||
|
||||
location / {
|
||||
root html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
#error_page 404 /404.html;
|
||||
|
||||
# redirect server error pages to the static page /50x.html
|
||||
#
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
|
||||
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# proxy_pass http://127.0.0.1;
|
||||
#}
|
||||
|
||||
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# root html;
|
||||
# fastcgi_pass 127.0.0.1:9000;
|
||||
# fastcgi_index index.php;
|
||||
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
||||
# include fastcgi_params;
|
||||
#}
|
||||
|
||||
# deny access to .htaccess files, if Apache's document root
|
||||
# concurs with nginx's one
|
||||
#
|
||||
#location ~ /\.ht {
|
||||
# deny all;
|
||||
#}
|
||||
}
|
||||
|
||||
|
||||
# another virtual host using mix of IP-, name-, and port-based configuration
|
||||
#
|
||||
#server {
|
||||
# listen 8000;
|
||||
# listen somename:8080;
|
||||
# server_name somename alias another.alias;
|
||||
|
||||
# location / {
|
||||
# root html;
|
||||
# index index.html index.htm;
|
||||
# }
|
||||
#}
|
||||
|
||||
|
||||
# HTTPS server
|
||||
#
|
||||
#server {
|
||||
# listen 443 ssl;
|
||||
# server_name localhost;
|
||||
|
||||
# ssl_certificate cert.pem;
|
||||
# ssl_certificate_key cert.key;
|
||||
|
||||
# ssl_session_cache shared:SSL:1m;
|
||||
# ssl_session_timeout 5m;
|
||||
|
||||
# ssl_ciphers HIGH:!aNULL:!MD5;
|
||||
# ssl_prefer_server_ciphers on;
|
||||
|
||||
# location / {
|
||||
# root html;
|
||||
# index index.html index.htm;
|
||||
# }
|
||||
#}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
# Ver: 3.0 by Endial Fang (endial@126.com)
|
||||
#
|
||||
# Docker 镜像构建脚本 - 主入口
|
||||
|
||||
# 编译后镜像名称
|
||||
export IMAGE_NAME="nginx"
|
||||
# 依赖镜像的仓库地址
|
||||
export REGISTRY_URL="swr.cn-north-4.myhuaweicloud.com/colovu/"
|
||||
# 源仓库地址(本地编译时,使用阿里云源仓库)
|
||||
export APT_SOURCE="aliyun"
|
||||
# 针对无法直接下载到软件包,本地变异时,使用缓存的软件包
|
||||
export LOCAL_URL="http://pkgs.colovu.com/dist"
|
||||
|
||||
# 引入本地构建脚本
|
||||
if [ -f ".ci/common/build_local.sh" ]; then
|
||||
# 执行本地构建脚本并传递参数
|
||||
exec ".ci/common/build_local.sh" "$@"
|
||||
else
|
||||
echo "Error: .ci/common/build_local.sh script not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
# Ver: 1.3 by Endial Fang (endial@126.com)
|
||||
#
|
||||
# 应用通用业务处理函数
|
||||
|
||||
. /usr/local/lib/libcommon.sh # 通用函数库
|
||||
|
||||
. /usr/local/lib/libfile.sh
|
||||
. /usr/local/lib/libfs.sh
|
||||
. /usr/local/lib/liblog.sh
|
||||
. /usr/local/lib/libos.sh
|
||||
. /usr/local/lib/libservice.sh
|
||||
. /usr/local/lib/libvalidations.sh
|
||||
|
||||
# 检测应用相应的配置文件是否存在,如果不存在,则从默认配置文件目录拷贝一份
|
||||
# 默认配置文件路径:/etc/${APP_NAME}
|
||||
# 目标配置文件路径:/srv/conf/${APP_NAME}
|
||||
# 参数:
|
||||
# $1 - 目标路径
|
||||
# $2 - 源路径
|
||||
# $* - 基础路径下的文件及目录列表,以" "分割
|
||||
# 例子:
|
||||
# ensure_config_file_exist /etc/${APP_NAME} conf.d server.conf
|
||||
app_ensure_config_file_exist() {
|
||||
local -r dist_path="${1:?dist paths is missing}"
|
||||
local -r base_path="${2:?source paths is missing}"
|
||||
local f=""
|
||||
|
||||
shift 2
|
||||
debug "List to check in ${base_path}: $@"
|
||||
while [ "$#" -gt 0 ]; do
|
||||
f="${1}"
|
||||
debug " Process \"${f}\""
|
||||
if [ -d "${base_path}/${f}" ]; then
|
||||
[[ ! -d "${dist_path}/${f}" ]] && debug " Create directory: ${dist_path}/${f}" && mkdir -p "${dist_path}/${f}"
|
||||
[[ ! -z $(ls -A "${base_path}/${f}") ]] && app_ensure_config_file_exist "${dist_path}/${f}" "${base_path}/${f}" $(ls -A "${base_path}/${f}")
|
||||
else
|
||||
[[ ! -e "${dist_path}/${f}" ]] && debug " Copy: ${base_path}/${f} to ${dist_path}" && cp "${base_path}/${f}" "${dist_path}"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/dumb-init /bin/bash
|
||||
# Ver: 1.5 by Endial Fang (endial@126.com)
|
||||
#
|
||||
# 容器入口脚本;当前脚本执行完毕时,使用默认用户执行镜像 CMD 定义的命令(默认为'/usr/local/bin/run.sh')
|
||||
|
||||
# 设置 shell 执行参数,可使用'-'(打开)'+'(关闭)控制。常用:
|
||||
# -e: 命令执行错误则报错(errexit); -u: 变量未定义则报错(nounset); -x: 打印实际待执行的命令行; -o pipefail: 设置管道中命令遇到失败则报错
|
||||
set -euo pipefail
|
||||
|
||||
. /usr/local/lib/libcommon.sh # 加载通用函数库
|
||||
|
||||
. /usr/local/bin/environment.sh # 设置环境变量
|
||||
|
||||
info "** Processing entry.sh **"
|
||||
|
||||
# 优先处理'-'开始的版本信息、帮助信息显示命令,如果是该类命令,处理后退出容器
|
||||
[[ "${1:0:1}" == '-' ]] && set -- "${APP_EXEC:-/bin/bash}" "$@" && print_command_help "$@"
|
||||
|
||||
# 处理 root 用户**且**使用默认启动脚本时的初始化
|
||||
if [[ "$(id -u)" == '0' ]] && [[ "$1" == "run.sh" ]]; then
|
||||
print_welcome_info
|
||||
/usr/local/bin/setup.sh
|
||||
|
||||
# 执行应用启动脚本并替换当前进程
|
||||
exec gosu "${APP_USER}" "$@"
|
||||
fi
|
||||
|
||||
# 处理非以上情形的自定义命令
|
||||
info "Start container with command: $@"
|
||||
exec "$@"
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
# Ver: 1.2 by Endial Fang (endial@126.com)
|
||||
#
|
||||
# 应用环境变量定义及初始化
|
||||
|
||||
export ENV_DEBUG=${ENV_DEBUG:-false}
|
||||
export ALLOW_ANONYMOUS="${ALLOW_ANONYMOUS:-no}"
|
||||
|
||||
# 通过读取变量名对应的`*_FILE`文件,获取变量值
|
||||
# 变量优先级: *_FILE > 传入变量 > 默认值
|
||||
app_env_file_lists=(
|
||||
APP_PASSWORD
|
||||
)
|
||||
for env_var in "${app_env_file_lists[@]}"; do
|
||||
file_env_var="${env_var}_FILE"
|
||||
if [[ -n "${!file_env_var:-}" ]]; then
|
||||
export "${env_var}=$(< "${!file_env_var}")"
|
||||
unset "${file_env_var}"
|
||||
fi
|
||||
done
|
||||
unset app_env_file_lists
|
||||
|
||||
# 应用路径参数(Dockerfile 已定义:APP_NAME、APP_VER,可能定义 APP_USER、APP_EXEC)
|
||||
export APP_EXEC="${APP_EXEC:-${APP_NAME}}"
|
||||
export APP_USER="${APP_USER:-${APP_NAME}}"
|
||||
export APP_GROUP="${APP_USER:-${APP_NAME}}"
|
||||
export APP_HOME="${APP_HOME:-/srv/${APP_NAME}}"
|
||||
export APP_BASE="${APP_BASE:-/usr/local/${APP_NAME}}"
|
||||
|
||||
export APP_DEF_DIR="${APP_BASE}/etc/${APP_NAME}"
|
||||
export APP_CONF_DIR="/srv/${APP_NAME}/conf"
|
||||
export APP_DATA_DIR="/srv/${APP_NAME}/data"
|
||||
export APP_CERT_DIR="/srv/${APP_NAME}/cert"
|
||||
export APP_LOG_DIR="/srv/${APP_NAME}/log"
|
||||
export APP_CACHE_DIR="/var/cache/${APP_NAME}"
|
||||
export APP_RUN_DIR="/var/run/${APP_NAME}"
|
||||
|
||||
# 应用配置参数
|
||||
export APP_CONF_FILE=${APP_CONF_DIR}/nginx.conf
|
||||
export APP_PID_FILE="${APP_PID_FILE:-/var/run/${APP_NAME}/${APP_NAME}.pid}"
|
||||
|
||||
# 个性化变量
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
# Ver: 1.5 by Endial Fang (endial@126.com)
|
||||
#
|
||||
# 应用启动脚本;组合默认的配置参数及容器启动时传入的 CMD 参数,启动应用
|
||||
|
||||
# 设置 shell 执行参数,可使用'-'(打开)'+'(关闭)控制。常用:
|
||||
# -e: 命令执行错误则报错(errexit); -u: 变量未定义则报错(nounset); -x: 打印实际待执行的命令行; -o pipefail: 设置管道中命令遇到失败则报错
|
||||
set -euo pipefail
|
||||
|
||||
. /usr/local/lib/liblog.sh # 日志输出函数库
|
||||
|
||||
. /usr/local/bin/environment.sh # 设置环境变量
|
||||
|
||||
info "** Processing run.sh **"
|
||||
readonly START_COMMAND="$(command -v ${APP_EXEC:-${APP_NAME}})"
|
||||
|
||||
# 配置默认启动参数(应用配置文件、前台方式启动)
|
||||
flags=()
|
||||
[[ -n "${APP_CONF_FILE:-}" ]] && flags+=("-c" "${APP_CONF_FILE}")
|
||||
[[ -n "${APP_EXTRA_FLAGS:-}" ]] && flags+=("${APP_EXTRA_FLAGS[@]}")
|
||||
flags+=("$@")
|
||||
|
||||
info "Start ${APP_NAME} with command: ${START_COMMAND[@]} ${flags[@]}"
|
||||
exec "${START_COMMAND[@]}" "${flags[@]}"
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# Ver: 1.3 by Endial Fang (endial@126.com)
|
||||
#
|
||||
# 应用环境及依赖文件设置脚本;当前脚本以‘root’用户执行
|
||||
|
||||
# 设置 shell 执行参数,可使用'-'(打开)'+'(关闭)控制。常用:
|
||||
# -e: 命令执行错误则报错(errexit); -u: 变量未定义则报错(nounset); -x: 打印实际待执行的命令行; -o pipefail: 设置管道中命令遇到失败则报错
|
||||
set -euo pipefail
|
||||
|
||||
. /usr/local/lib/libcommon.sh # 加载通用函数库
|
||||
. /usr/local/lib/libfs.sh # 加载文件操作函数库
|
||||
. /usr/local/lib/libos.sh # 加载系统管理函数库
|
||||
|
||||
. /usr/local/bin/environment.sh # 设置环境变量
|
||||
. /usr/local/bin/common.sh # 应用专用函数库
|
||||
|
||||
info "** Processing setup.sh **"
|
||||
|
||||
APP_DIRS=(/var/log/${APP_NAME} /var/run/${APP_NAME} /var/cache/${APP_NAME} ${APP_HOME})
|
||||
APP_DIRS+=(${APP_HOME}/conf ${APP_HOME}/data ${APP_HOME}/cert ${APP_HOME}/log)
|
||||
|
||||
info "Ensure directory exists: ${APP_DIRS[@]}"
|
||||
for dir in ${APP_DIRS[@]}; do
|
||||
ensure_dir_exists ${dir}
|
||||
done
|
||||
|
||||
# 动态权限处理
|
||||
current_uid=$(id -u)
|
||||
current_gid=$(id -g)
|
||||
# 确保当前用户对必要目录有访问权限
|
||||
for dir in ${APP_DIRS[@]}; do
|
||||
if [ -d "$dir" ]; then
|
||||
chown $current_uid:$current_gid $dir
|
||||
fi
|
||||
done
|
||||
|
||||
# 检测指定文件是否在配置文件存储目录存在,如果不存在则拷贝(新挂载数据卷、手动删除都会导致不存在)
|
||||
info "Check config files in: ${APP_CONF_DIR}"
|
||||
if [[ -z "$(ls -A "${APP_CONF_DIR}")" ]]; then
|
||||
app_ensure_config_file_exist "${APP_CONF_DIR}" "${APP_DEF_DIR}" $(ls -A "${APP_DEF_DIR}")
|
||||
fi
|
||||
|
||||
# 解决使用non-root后,[emerg] open() "/dev/stdout" failed (13: Permission denied)
|
||||
debug "Change permissions of stdout/stderr to 0662"
|
||||
chmod 0662 /dev/stdout /dev/stderr
|
||||
@@ -0,0 +1,78 @@
|
||||
server {
|
||||
listen 8080;
|
||||
server_name localhost;
|
||||
|
||||
charset utf-8;
|
||||
|
||||
access_log /srv/nginx/log/default.access.log main;
|
||||
error_log /srv/nginx/log/default.error.log warn;
|
||||
|
||||
location / {
|
||||
root /usr/local/nginx/html;
|
||||
index index.html index.htm index.php;
|
||||
autoindex on;
|
||||
}
|
||||
|
||||
#error_page 404 /404.html;
|
||||
|
||||
# redirect server error pages to the static page /50x.html
|
||||
#
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/local/nginx/html;
|
||||
}
|
||||
|
||||
# 将 PHP 脚本解析请求转发至提供 FastCGI 服务的容器中,如 php-fpm:9000
|
||||
# Docker 镜像,尽量避免使用 UNIX Domain Socket 方式
|
||||
#location ~ \.php$ {
|
||||
# root /usr/local/nginx/html;
|
||||
# fastcgi_pass php-fpm:9000;
|
||||
# #fastcgi_pass unix:/var/run/php5/php-fpm.sock;
|
||||
# fastcgi_index index.php;
|
||||
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
# include /usr/local/nginx/fastcgi_params;
|
||||
#}
|
||||
|
||||
# deny access to .htaccess files, if Apache's document root
|
||||
# concurs with nginx's one
|
||||
#location ~ /\.ht {
|
||||
# deny all;
|
||||
#}
|
||||
}
|
||||
|
||||
# another virtual host using mix of IP-, name-, and port-based configuration
|
||||
#
|
||||
#server {
|
||||
# listen 8000;
|
||||
# listen somename:8080;
|
||||
# server_name somename alias another.alias;
|
||||
#
|
||||
# location / {
|
||||
# root /srv/conf/nginx/html/;
|
||||
# index index.html index.htm;
|
||||
# }
|
||||
#}
|
||||
|
||||
|
||||
# HTTPS server
|
||||
#
|
||||
#server {
|
||||
# listen 8443 ssl;
|
||||
# server_name localhost;
|
||||
#
|
||||
# ssl_certificate /srv/cert/nginx/cert.pem;
|
||||
# ssl_certificate_key /srv/cert/nginx/cert.key;
|
||||
#
|
||||
# ssl_session_cache shared:SSL:1m;
|
||||
# ssl_session_timeout 5m;
|
||||
#
|
||||
# ssl_protocols SSLv2 SSLv3 TLSv1.2;
|
||||
# ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256:AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
|
||||
# ssl_ciphers HIGH:!aNULL:!MD5;
|
||||
# ssl_prefer_server_ciphers on;
|
||||
#
|
||||
# location / {
|
||||
# root /usr/local/nginx/html/;
|
||||
# index index.html index.htm;
|
||||
# }
|
||||
#}
|
||||
@@ -0,0 +1,2 @@
|
||||
# 虚拟服务定义文件
|
||||
# 文件名默认为:<service-name>.conf
|
||||
@@ -0,0 +1,167 @@
|
||||
# /etc/nginx/nginx.conf
|
||||
|
||||
# 针对 Docker 镜像使用时,使用预定义的用户
|
||||
# user nginx;
|
||||
|
||||
# 关闭守护进程模式。如果设置为后台守护进程模式,容器在启动应用后会退出
|
||||
daemon off;
|
||||
|
||||
# 根据 CPU 核心数设置进程数量并开启CPU亲和机制
|
||||
worker_processes auto;
|
||||
worker_cpu_affinity auto;
|
||||
|
||||
# 手动设置进程数量。子进程个数最好跟CPU的核心数一样
|
||||
# worker_processes 8;
|
||||
# 手动绑定子进程与 CPU 核心,避免进程切换造成性能损失
|
||||
# worker_cpu_affinity 0001 0010 0100 1000 0011 0110 1100 1001;
|
||||
|
||||
# 启用 JIT 以加速正则表达式处理
|
||||
pcre_jit on;
|
||||
|
||||
# 配置默认的日志输出方式。可以为日志文件或标准输出设备,日志文件路径固定不可修改
|
||||
# 输出级别:notice / info / warn / error / 为空
|
||||
# error_log /srv/nginx/log/error.log warn;
|
||||
# error_log /srv/nginx/log/error.log info;
|
||||
# error_log /srv/nginx/log/error.log notice;
|
||||
# error_log /srv/nginx/log/error.log;
|
||||
|
||||
# 包含配置文件,以加载动态模块
|
||||
include /usr/local/nginx/modules/*.conf;
|
||||
|
||||
# 设置PID文件路径为对应的子目录
|
||||
pid /var/run/nginx/nginx.pid;
|
||||
|
||||
# 增加文件描述符限制
|
||||
worker_rlimit_nofile 65535;
|
||||
|
||||
events {
|
||||
# 使用 epoll 模型
|
||||
use epoll;
|
||||
|
||||
# 设置一个进程可以打开的最大并发链接数量
|
||||
worker_connections 4096;
|
||||
multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
# 如果启用Ruby支持,需要编译支持Ruby的版本,在这里配置启用对应版本的Passenger
|
||||
# passenger_root /usr/local/rvm/gems/ruby-2.1.3/gems/passenger-4.0.57;
|
||||
# passenger_ruby /usr/local/rvm/gems/ruby-2.1.3/wrappers/ruby;
|
||||
|
||||
# 包含扩展名与类型映射定义 MIME 文件,并定义默认使用的类型
|
||||
include /srv/nginx/conf/mime.types;
|
||||
default_type application/octet-stream;
|
||||
charset UTF-8;
|
||||
|
||||
# 开启零拷贝机制
|
||||
sendfile on;
|
||||
|
||||
# 不缓存直接发送(禁用Nagle算法),一般用于开启了长连接的情况下使用
|
||||
# 用于对响应速度要求较高的场景,如IM、金融等
|
||||
tcp_nodelay on;
|
||||
|
||||
# 拼包后发送(一个MTU或超时),与 tcp_nodelay 互斥,且需要配合 sendfile 使用
|
||||
# 用于对吞吐量要求比较高的场景,如调度、报表等
|
||||
# tcp_nopush on;
|
||||
|
||||
# 对客户端隐藏服务器版本
|
||||
server_tokens off;
|
||||
|
||||
# 安全头部设置
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
|
||||
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||
|
||||
# 客户端上传文件大小限制,超出时返回错误代码 413。
|
||||
# 默认值:1m;设置为 0 时禁用该限制
|
||||
client_max_body_size 1024m;
|
||||
|
||||
# Name servers used to resolve names of upstream servers into addresses.
|
||||
# It's also needed when using tcpsocket and udpsocket in Lua modules.
|
||||
# resolver 208.67.222.222 208.67.220.220;
|
||||
|
||||
# 优化服务器域名散列表
|
||||
server_names_hash_bucket_size 64;
|
||||
server_names_hash_max_size 2048;
|
||||
|
||||
# 连接超时时间,默认值:65秒
|
||||
keepalive_timeout 65;
|
||||
|
||||
# 读取客户端请求头超时时间,默认值:60秒
|
||||
client_header_timeout 60;
|
||||
|
||||
# 读取客户端请求体超时时间,默认值:60秒
|
||||
client_body_timeout 60;
|
||||
|
||||
# 临时文件路径
|
||||
client_body_temp_path /tmp/client_body_temp;
|
||||
fastcgi_temp_path /tmp/fastcgi_temp;
|
||||
proxy_temp_path /tmp/proxy_temp;
|
||||
scgi_temp_path /tmp/scgi_temp;
|
||||
uwsgi_temp_path /tmp/uwsgi_temp;
|
||||
|
||||
proxy_buffer_size 128k;
|
||||
proxy_buffering on;
|
||||
proxy_buffers 4 64k;
|
||||
proxy_busy_buffers_size 128k;
|
||||
proxy_max_temp_file_size 1024m;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# Path of the file with Diffie-Hellman parameters for EDH ciphers.
|
||||
# ssl_dhparam /etc/ssl/nginx/dh2048.pem;
|
||||
|
||||
# Specifies that our cipher suits should be preferred over client ciphers.
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
# Enables a shared SSL cache with size that can hold around 8000 sessions.
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 5m;
|
||||
|
||||
# 启用或禁用应答信息的压缩传输
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_comp_level 6;
|
||||
gzip_types text/plain text/css text/xml application/xml application/javascript text/javascript application/json application/x-javascript text/xml;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_http_version 1.1;
|
||||
gzip_proxied no-cache no-store private expired auth;
|
||||
gzip_disable "MSIE [1-6]\.";
|
||||
|
||||
# Enable checking the existence of precompressed files.
|
||||
# gzip_static on;
|
||||
|
||||
# 定义日志格式
|
||||
# log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
log_format main '{"time_local": "$time_local", '
|
||||
'"path": "$request_uri", '
|
||||
'"ip": "$remote_addr", '
|
||||
'"time": "$time_iso8601", '
|
||||
'"user_agent": "$http_user_agent", '
|
||||
'"user_id_got": "$uid_got", '
|
||||
'"user_id_set": "$uid_set", '
|
||||
'"remote_user": "$remote_user", '
|
||||
'"request": "$request", '
|
||||
'"status": "$status", '
|
||||
'"body_bytes_sent": "$body_bytes_sent", '
|
||||
'"request_time": "$request_time", '
|
||||
'"http_referrer": "$http_referer" }';
|
||||
|
||||
# 设置日志输出的路径、格式
|
||||
# access_log /srv/nginx/log/access.log main;
|
||||
# error_log /srv/nginx/log/error.log warn;
|
||||
access_log /dev/stdout main;
|
||||
error_log /dev/stdout warn;
|
||||
|
||||
# 包含虚拟服务器定义配置文件
|
||||
include /srv/nginx/conf/conf.d/*.conf;
|
||||
}
|
||||
|
||||
# 包含其它类型服务配置文件,如 RTMP
|
||||
include /srv/nginx/conf/services/*.conf;
|
||||
@@ -0,0 +1,13 @@
|
||||
# 其他类型的服务定义文件
|
||||
# 文件名默认为:<service-name>.conf
|
||||
|
||||
# 优化作为代理服务时的长连接配置,减少握手次数,降低服务器损耗
|
||||
|
||||
upstream xxx {
|
||||
# 长连接数
|
||||
keepalive 32;
|
||||
# 每个长连接提供的最大请求数
|
||||
keepalived_requests 100;
|
||||
# 每个长连接没有新的请求时,保持的最长时间
|
||||
keepalive_timeout 60s;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash -e
|
||||
# Ver: 1.1 by Endial Fang (endial@126.com)
|
||||
#
|
||||
# 在安装完应用后,使用该脚本修改默认配置文件中部分配置项; 如果相应的配置项已经定义为容器环境变量,则不需要在这里修改
|
||||
|
||||
# 定义要修改的文件
|
||||
CONF_FILE="${APP_DEF_DIR}/nginx.conf"
|
||||
|
||||
echo "Process overrides for: ${CONF_FILE}"
|
||||
#sed -i -E 's/^listeners=/d' "${CONF_FILE}"
|
||||
#sed -i -E 's/^log.dirs=\/tmp\/kafka-logs*/log.dirs=\/var\/log\/kafka/g' "${CONF_FILE}"
|
||||
@@ -0,0 +1,9 @@
|
||||
version: '3.8'
|
||||
|
||||
# Docker-Compose 方式启动容器的 YAML 配置文件
|
||||
# 当前配置仅保证可以启动容器;更多配置参数请参考镜像 README.md 文档中说明
|
||||
services:
|
||||
nginx:
|
||||
image: 'registry.cn-shenzhen.aliyuncs.com/colovu/nginx:latest'
|
||||
ports:
|
||||
- '80:8080'
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Reference in New Issue
Block a user