1.Nginx文件备份
cd /www/server/nginx/sbin/ cp nginx nginx.bak
2.下载Nginx fancyindex模块
cd /root/ git clone https://github.com/aperezdc/ngx-fancyindex cp -R ./ngx-fancyindex /www/server/nginx/src
3.查看当前Nginx编译模块
nginx -V
4.编译Nginx
cd /www/server/nginx/src ./configure --user=www --group=www --prefix=/www/server/nginx \ --add-module=/www/server/nginx/src/ngx_devel_kit \ --add-module=/www/server/nginx/src/lua_nginx_module \ --add-module=/www/server/nginx/src/ngx_cache_purge \ --add-module=/www/server/nginx/src/nginx-sticky-module \ --with-openssl=/www/server/nginx/src/openssl \ --with-pcre=pcre-8.43 \ --with-http_v2_module \ --with-stream \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-http_image_filter_module \ --with-http_gzip_static_module \ --with-http_gunzip_module \ --with-ipv6 \ --with-http_sub_module \ --with-http_flv_module \ --with-http_addition_module \ --with-http_realip_module \ --with-http_mp4_module \ --with-ld-opt=-Wl,-E \ --with-cc-opt=-Wno-error \ --with-ld-opt=-ljemalloc \ --with-http_dav_module \ --add-module=/www/server/nginx/src/nginx-dav-ext-module \ --add-module=/www/server/nginx/src/ngx-fancyindex make
5.替换Nginx文件
nginx -s quit cp objs/nginx /www/server/nginx/sbin/ nginx
6.下载Nginx-Fancyindex-Theme主题
wget https://codeload.github.com/Naereen/Nginx-Fancyindex-Theme/zip/master unzip master cd Nginx-Fancyindex-Theme-master cp -rp Nginx-Fancyindex-Theme-light/ /www/wwwroot/test_dir/
7.在宝塔网站配置添加
location /files {
if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
add_header Content-Disposition attachment;
}
alias /data/download;
fancyindex on;
fancyindex_exact_size off;
fancyindex_localtime on;
fancyindex_header "/Nginx-Fancyindex-Theme-light/header.html";
fancyindex_footer "/Nginx-Fancyindex-Theme-light/footer.html";
fancyindex_ignore "examplefile.html";
fancyindex_ignore "Nginx-Fancyindex-Theme-light";
fancyindex_name_length 255;
}
8.重启Nginx
nginx -s reload
你可能也喜欢————

本站已稳定运行 1027 天