基于官方nginx-1.16.1.tar.gz
制作
Dockerfile
FROM alpine:3.13
LABEL maintainer="244655702@qq.com"
ADD nginx-1.16.1.tar.gz /data/tools
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk add --no-cache --virtual .build-deps \ # 安装编译依赖
gcc \
g++ \
make \
&& apk add --no-cache busybox-extras \ # 安装运行依赖和工具
curl \
tzdata \
pcre-dev \
openssl-dev \
zlib-dev \
&& cd /data/tools/nginx-1.16.1 \
&& sed -i 's/Server: nginx/Server: myserver/' src/http/ngx_http_header_filter_module.c \ # 修改Server token
&& sed -i 's/1.16.1/1.1/' src/core/nginx.h \ # 修改nginx -v信息
&& sed -i 's:nginx/:myserver/:' src/core/nginx.h \ # 修改nginx -v信息
&& sed -i 's:<center>nginx</center>:<center>myserver</center>:' src/http/ngx_http_special_response.c \ # 修改404,403返回页面中的字符串
&& ./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
&& make \
&& make install \
&& apk del .build-deps \ # 卸载编译依赖
&& cp -rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ # 设置时区
&& mkdir -p /data/logs/nginx/error \
&& rm -rf /data/tools \ # 删除编译目录
&& ln -s /usr/local/nginx/sbin/nginx /sbin/nginx
COPY nginx.conf /usr/local/nginx/conf/
CMD ["/usr/local/nginx/sbin/nginx" "-g" "daemon off;"]