下载ngx-fancyindex
[root@TKY ~]# git clone https://github.com/aperezdc/ngx-fancyindex [root@TKY ~]# pwd /root [root@TKY ~]# ls ngx-fancyindex
重新编译(安装编译)
[root@TKY package]# wget https://openresty.org/download/openresty-1.21.4.1.tar.gz [root@TKY package]# tar xf openresty-1.21.4.1.tar.gz [root@TKY package]# cd openresty-1.21.4.1/ [root@TKY openresty-1.21.4.1]# yum -y install gcc gcc-c++ pcre pcre-devel openssl openssl-devel [root@TKY openresty-1.21.4.1]# ./configure --prefix=/usr/local/openresty --with-cc-opt=-O2 --with-pcre --with-http_realip_module --with-http_sub_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-http_v2_module --with-stream --with-stream_ssl_preread_module --with-http_ssl_module --add-module=/root/ngx-fancyindex/ [root@TKY openresty-1.21.4.1]# gmake -j4 && gmake install [root@TKY openresty-1.21.4.1]# ps aux | grep openresty root 2144 0.0 0.0 57252 4368 ? Ss 2022 0:00 nginx: master process openresty root 16705 0.0 0.0 112832 988 pts/4 S+ 14:16 0:00 grep --color=auto openresty [root@TKY openresty-1.21.4.1]# kill 2144 [root@TKY openresty-1.21.4.1]# openresty [root@TKY openresty-1.21.4.1]# openresty -V nginx version: openresty/1.21.4.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -O2' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.21 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.11 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-pcre --with-http_realip_module --with-http_sub_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-http_v2_module --with-stream --with-stream_ssl_preread_module --with-http_ssl_module --add-module=/root/ngx-fancyindex --with-stream # 这里 configure arguments 出现 --add-module=/root/ngx-fancyindex 表示安装成功
Nginx配置
[root@TKY ~]# cat /usr/local/openresty/nginx/conf/www/download.conf server { listen 80; #listen 443 ssl; #server_name 域名; default_type application/json; #ssl_certificate ssl/域名证书文件.pem; #ssl_certificate_key ssl/域名证书文件.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; access_log logs/download.access.log main; error_log logs/download.error.log; root /data/download; # 网站目录 #location = /download/ { # lua脚本 可以不用 # content_by_lua_file /usr/local/openresty/nginx/conf/lua/download.lua; #} location / { fancyindex on; # 启用或禁用目录索引 fancyindex_exact_size off; # 定义如何在目录列表中表示文件大小:精确表示,或舍入为千字节、兆字节和千兆字节 fancyindex_localtime on; # 启用将文件时间显示为本地时间。默认值为“off”(GMT时间) fancyindex_time_format "%Y-%m-%d %H:%M:%S"; fancyindex_header "/Nginx-Fancyindex-Theme-light/header.html"; # 网站上半部文件 fancyindex_footer "/Nginx-Fancyindex-Theme-light/footer.html"; # 网站下半部文件 fancyindex_ignore "Nginx-Fancyindex-Theme-light"; # 忽略的目录 } }
配置网站模版
[root@TKY ~]# wget https://github.com/Naereen/Nginx-Fancyindex-Theme/archive/refs/heads/master.zip [root@TKY ~]# unzip master.zip [root@TKY ~]# mv Nginx-Fancyindex-Theme-master/Nginx-Fancyindex-Theme-light/ /data/download/ [root@TKY ~]# openresty -t [root@TKY ~]# openresty -s reload
优化
# nginx 配置文件添加以下配置 location ~ \.md$ { root /data/download/Nginx-Fancyindex-Theme-light; } # 对应如下文件 可以做 网站提示 和 使用方法 # /data/download/Nginx-Fancyindex-Theme-light/HEADER.md # /data/download/Nginx-Fancyindex-Theme-light/README.md # 不需要 可以将文件清空
# 网站备案号 # /data/download/Nginx-Fancyindex-Theme-light/footer.html # 将这个文件<footer>字段变成以下配置 备案号写自己的 <footer> <a href="https://beian.miit.gov.cn/#/Integrated/recordQuery" target="_blank">京ICP备2022xxxxxx号-</a> </footer>