# Docker ngx-fancyindex使用 ## ngx-fancyindex 项目 可以就是美化nginx文件列表的模块。 FancyIndex 模块可以生成文件列表,就像内置的自动索引 模块一样,但增加了一些风格。这是可能的,因为该模块允许对生成的内容进行一定程度的定制: - 自定义标头,本地或远程存储。 - 自定义页脚,本地或远程存储。 - 添加您自己的 CSS 样式规则。 - 允许选择按名称(默认)、修改时间或大小对元素进行排序;升序(默认)或降序。 模块项目地址: 本文使用主题: ## Docker编译 `Dockerfile`文件 ```dockerfile FROM alpine:latest WORKDIR /root COPY nginx-1.24.0 /root/nginx COPY ngx-fancyindex-0.5.2 /root/ngx-fancyindex # 配置中科大下载源 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \ # 更新 & 安装依赖 && apk update && apk add --no-cache gcc libc-dev make openssl-dev pcre-dev zlib-dev linux-headers curl \ # 切换工作目录 && cd /root/nginx \ # 执行编译安装 Nginx && ./configure --prefix=/etc/nginx \ # 指定安装扩展模块路径 --add-module=/root/ngx-fancyindex \ --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 \ --error-log-path=/dev/stderr \ --http-log-path=/dev/stdout \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client \ --http-proxy-temp-path=/var/cache/nginx/proxy \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi \ --http-scgi-temp-path=/var/cache/nginx/scgi \ --with-http_ssl_module \ --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-mail \ --with-mail_ssl_module \ --with-stream --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ # 编译安装 && make && make install \ # 移除源文件 && rm -rf /root/nginx /root/ngx-fancyindex \ # 创建目录 && mkdir -p /var/cache/nginx/client \ # 修改系统时区为东八区 && rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime EXPOSE 80 CMD ["/bin/sh","-c","nginx -g 'daemon off;'"] ``` `/etc/nginx/nginx.conf`示例配置 > 主题文件解压存放到根目录 ``` worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 60; server { listen 80; server_name 0.0.0.0; # 限制上传文件大小 0无限制 client_max_body_size 0; location / { # 文件目录 root /data; fancyindex on; # 使用本地时间 fancyindex_localtime on; fancyindex_exact_size off; # 从网站的根目录 引入样式 fancyindex_header "/Nginx-Fancyindex-Theme-dark/header.html"; fancyindex_footer "/Nginx-Fancyindex-Theme-dark/footer.html"; # 文件列表忽略的文件 fancyindex_ignore "Nginx-Fancyindex-Theme-dark"; } } } ```