wget http://nginx.org/download/nginx-1.28.0.tar.gz
wget https://github.com/aperezdc/ngx-fancyindex/releases/download/v0.5.2/ngx-fancyindex-0.5.2.tar.xz
tar -xzvf nginx-1.28.0.tar.gz && tar -xvJf ngx-fancyindex-0.5.2.tar.xz
FROM alpine:latest
# 维护者信息
LABEL maintainer="kob@qq.com"
WORKDIR /root
# 复制 Nginx 源码
COPY ./nginx-1.28.0 /root/nginx-1.28.0
COPY ./ngx-fancyindex-0.5.2 /root/ngx-fancyindex-0.5.2
# 创建系统用户和组
RUN addgroup -S -g 101 nginx \
&& adduser -S -D -H -s /bin/false -u 101 -G nginx -h /nonexistent -g "nginx user" nginx \
&& apk update \
&& apk add --no-cache \
gcc \
musl-dev \
pcre-dev \
openssl-dev \
zlib-dev \
make \
curl \
linux-headers \
perl \
libaio-dev \
&& cd /root/nginx-1.28.0/ && \
./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 \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-perl_modules_path=/usr/lib/perl5/vendor_perl \
--user=nginx \
--group=nginx \
--with-compat \
--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 \
--with-cc-opt='-Os -fstack-clash-protection -Wformat -Werror=format-security -fno-plt -g' \
--with-ld-opt='-Wl,--as-needed,-O1,--sort-common -Wl,-z,pack-relative-relocs' \
--add-module=../ngx-fancyindex-0.5.2 \
&& make -j$(nproc) \
&& make install \
&& mkdir -p /var/cache/nginx/client_temp \
&& chown -R nginx:nginx /var/cache/nginx \
&& rm -rf /root/nginx-1.28.0 \
&& rm -rf /root/ngx-fancyindex-0.5.2 \
# 设置时区为东八区
&& apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
# && apk del tzdata gcc musl-dev pcre-dev openssl-dev zlib-dev make curl linux-headers perl libaio-dev \
&& apk del tzdata gcc make curl perl \
# 清理缓存
&& rm -rf /var/cache/apk/*
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
docker build nginx-fancyindex:alpine .