← Back to list
2026-06-01T02:26:17.367ZLinuxNginx

一分钟键封装nginx模块

一键封装nginx模块

本文将指导您如何使用 Docker 快速封装第三方模块。通过一个简单的 Dockerfile 和构建脚本,您可以轻松地在一分钟内创建符合自己需求的 Nginx 环境。

  1. Dockerfile
FROM registry.cn-shenzhen.aliyuncs.com/starbucket/nginx:base

WORKDIR /opt/nginx

RUN mkdir -p /opt/nginx/modules /opt/nginx/logs \
    && ln -sf /dev/stdout /opt/nginx/logs/access.log \
    && ln -sf /dev/stderr /opt/nginx/logs/error.log

# 安装LuaJIT 2.1
ENV LUAJIT_LIB=/usr/local/lib \
    LUAJIT_INC=/usr/local/include/luajit-2.1 \
    PATH="/usr/local/bin:${PATH}" \
    LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"
RUN git clone --depth 1 --branch v2.1-agentzh https://github.com/openresty/luajit2.git /tmp/LuaJIT \
    && make -C /tmp/LuaJIT -j"$(nproc)" \
    && make -C /tmp/LuaJIT install PREFIX=/usr/local \
    && ldconfig /usr/local/lib 2>/dev/null || true \
    && rm -rf /tmp/LuaJIT

# 安装第三方模块源码
RUN git clone https://github.com/arut/nginx-rtmp-module.git /opt/nginx/modules/nginx-rtmp-module

# 编译 nginx
RUN chmod +x build.sh
# 追加额外静态模块
RUN ./build.sh --add-module=/opt/nginx/modules/nginx-rtmp-module


# 清理模块源码
RUN rm -rf ./build.sh
RUN rm -rf modules/nginx-rtmp-module

# 检查nginx版本
RUN echo "==> 检查 nginx 版本和模块" \
    && nginx -V 2>&1
    

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Comments & discussion

The first comment in each thread opens a topic. Signed-in readers can keep the conversation going under that topic.

No comments yet. Sign in to start a topic.

Start a new topic

Sign in to start a topic or join the discussion.