我需要在 NGINX 官方 Docker 映像中更改什么才能拥有 set-misc-nginx 模块? [英] What do I need to change in NGINX official Docker's image to have the set-misc-nginx module?
问题描述
我需要使用来自这个库的随机数生成器,但我想使用 官方 nginx 映像,所以我试图查看其源代码并执行安装此库所需的更改.
I need to use the random number generator from this library, but I wanted to use the official nginx image, so I was trying to see its source code and perform the changes required to have this library installed.
但我不知所措,因为这些说明似乎与 NGINX 在该 Dockerfile 中的安装方式不符.
But I am at loss, as the instructions don't seem to fit with the way NGINX is being installed in that Dockerfile.
如何在官方 NGINX Dockerfile 中安装 set-misc-nginx?
How can I install set-misc-nginx within the official NGINX Dockerfile?
推荐答案
您可以扩展官方的ngnix 构建动态模块,然后在 nginx
中加载它们:
You can extend the official ngnix to build the dynamic modules then load them in nginx
:
# syntax=docker/dockerfile:experimental
ARG NGINX_VERSION
FROM nginx:${NGINX_VERSION} as build
RUN apt-get update &&
apt-get install -y
openssh-client
git
wget
libxml2
libxslt1-dev
libpcre3
libpcre3-dev
zlib1g
zlib1g-dev
openssl
libssl-dev
libtool
automake
gcc
g++
make &&
rm -rf /var/cache/apt
RUN wget "http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" &&
tar -C /usr/src -xzvf nginx-${NGINX_VERSION}.tar.gz
RUN mkdir -p -m 0600 ~/.ssh &&
ssh-keyscan github.com >> ~/.ssh/known_hosts
WORKDIR /src/ngx_devel_kit
RUN --mount=type=ssh git clone git@github.com:simpl/ngx_devel_kit .
WORKDIR /src/set-misc-nginx-module
RUN --mount=type=ssh git clone git@github.com:openresty/set-misc-nginx-module.git .
WORKDIR /usr/src/nginx-${NGINX_VERSION}
RUN NGINX_ARGS=$(nginx -V 2>&1 | sed -n -e 's/^.*arguments: //p')
./configure --with-compat --with-http_ssl_module --add-dynamic-module=/src/ngx_devel_kit --add-dynamic-module=/src/set-misc-nginx-module ${NGINX_ARGS} &&
make modules
FROM nginx:${NGINX_VERSION}
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/nginx-${NGINX_VERSION}/objs/ngx_http_set_misc_module.so /usr/src/nginx-${NGINX_VERSION}/objs/ndk_http_module.so /usr/lib/nginx/modules/
注意:这个例子是一个多使用 docker
的分阶段构建 构建增强 克隆存储库(取决于您的 docker
版本,您可能需要 启用实验功能).
Note: this example is a multi-staged build that uses the docker
build enhancements to clone the repositories (depending on your version of docker
you may have to enable experimental features).
您可以在复制到最终映像中的 nginx.conf
中加载模块:
You can load the modules in the nginx.conf
that's copied in the final image:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
load_module /usr/lib/nginx/modules/ndk_http_module.so;
load_module /usr/lib/nginx/modules/ngx_http_set_misc_module.so;
events {
worker_connections 1024;
}
http {
...
}
构建镜像:DOCKER_BUILDKIT=1 docker build --rm --ssh=default --build-arg NGINX_VERSION=1.17.3 --network host -t so:57739560 .
运行容器:docker run --rm -it -p 80:80 so:57739560
有关使用官方 nginx
图像构建动态模块的另一个示例,您可以查看我的 nginx-modsecurity 存储库(nginx
图像扩展为 Modsecurity 和 Modsecurity-nginx).
For another example of building dynamic modules using the official nginx
image you can check out my nginx-modsecurity repo (nginx
image extended with Modsecurity and Modsecurity-nginx).
这篇关于我需要在 NGINX 官方 Docker 映像中更改什么才能拥有 set-misc-nginx 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!