目 录CONTENT

文章目录

构建支持nginx-dav-ext-module的nginx镜像

成培培
2024-10-18 / 0 评论 / 0 点赞 / 40 阅读 / 0 字

需求来源

起初想在家里软路由上的nginx里配置webdav相关支持实现轻NAS功能,结果发现我使用的官方nginx镜像并没有安装nginx-dav-ext-module模块,于是找到了nginx官方的提供的dockerfile文件,准备进行修改追加上该模块。

我使用的nginx版本1.26.2对应的Dockerfile: https://github.com/nginxinc/docker-nginx/blob/e78cf70ce7b73a0c9ea734c9cf8aaaa283c1cc5a/stable/debian/Dockerfile

遇到的问题

官方构建nginx镜像使用的是apt安装,并不是源码编译,所以我这里没法再编译时增加模块,所以我想到直接用apt命令安装dav扩展的模块

apt install -y nginx-extras

我在ubuntu虚拟机上这么安装nginx以及相关扩展包没有问题,但是在官方的Dockerfile镜像中增加该命令结果构建报错了,原因是版本冲突了

解决方案

最后决定干脆不修改官方的镜像的,基于ubuntu镜像、nginx源码以及nginx-dav-ext-module模块定制一个景象,之所以选择ubuntu是因为我在虚拟机上编译成功了,所以应该不会有什么问题,无非就是最终构建出来的镜像比较大,自己用也无所谓了。

源码

Github地址:https://github.com/chengpei/nginx-ubuntu-ext-dav

其中nginx-1.26.2.tar.gz 是下载的nginx源码,然后在其中增加了nginx-dav-ext-module模块的源码压缩放一起的,你也可以自己下载需要的版本进行替换

nginx源码:https://github.com/nginx/nginx

dav-ext源码:https://github.com/arut/nginx-dav-ext-module

sh脚本是参考nginx官方镜像启动方式增加的脚本

以下是dockerfile文件的内容:

FROM ubuntu:24.04

ADD nginx-1.26.2.tar.gz /

RUN sed -i 's/http:\/\/archive.ubuntu.com\/ubuntu\//http:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu\//g' /etc/apt/sources.list.d/ubuntu.sources

RUN apt-get update

RUN apt-get install -y gcc make libpcre3-dev libssl-dev zlib1g-dev libxml2-dev libxslt-dev libgd-dev libgeoip-dev git

RUN cd /nginx-1.26.2 && \

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --user=root --group=root --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_v3_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=./nginx-dav-ext-module && make -j && make install

RUN mkdir /docker-entrypoint.d

COPY docker-entrypoint.sh /

COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d

COPY 15-local-resolvers.envsh /docker-entrypoint.d

COPY 20-envsubst-on-templates.sh /docker-entrypoint.d

COPY 30-tune-worker-processes.sh /docker-entrypoint.d

ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 80

STOPSIGNAL SIGQUIT

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

主要就是基于ubuntu镜像,把nginx相关源码丢进去,然后安装编译需要的工具库,编译源码安装。

在源码当前目录执行命令构建:

docker build -t nginx:1.26.2-ubuntu-ext .

构建成功即可运行一个具有dav-ext支持的nginx镜像

docker run --restart=always -p80:80 --name nginx-ext -d nginx:1.26.2-ubuntu-ext

0

评论区