使用nginx fancyindex 模块打造下载站点
cd ~
mkdir build
cd build
#先运行 nginx -v 查看下当前系统的nginx版本, 我这里的结果是 nginx version: nginx/1.14.2
#因此,下载1.14.2的nignx
NGX_VER=1.14.2
wget https://nginx.org/download/nginx-$NGX_VER.tar.gz
tar xvzf nginx-$NGX_VER.tar.gz
git clone https://github.com/aperezdc/ngx-fancyindex.git
cd nginx-$NGX_VER
./configure --add-dynamic-module=../ngx-fancyindex --with-compat
make -j4
编译成功后,可以找到 ./objs/ngx_http_fancyindex_module.so
这个文件
复制到nginx配置目录:
sudo mkdir /etc/nginx/modules
sudo cp -v ./objs/ngx_http_fancyindex_module.so /etc/nginx/modules/
先修改nginx主配置文件:/etc/nginx/nginx.conf
我们在顶部添加:
load_module "modules/ngx_http_fancyindex_module.so";
主题文件:git clone https://gitee.com/8ox86/TheInsomniac-Nginx-Fancyindex-Theme.git
主题文件需放到下载目录里
站点配置文件内容:
server {
server_name rom.nanodm.localhost;
listen 80;
charset utf-8;
#rewrite_log on;
access_log /var/log/nginx/rom.access.log main;
error_log /var/log/nginx/rom.error.log info;
#此处 /srv/http 为要开放浏览的目录
root /srv/http;
index index.html index.htm;
error_page 404 /404.html;
location / {
#pagespeed off;
include /etc/nginx/modules/fancyindex/fancyindex.conf;
}
#fixup fancyindex subrequest
location ^~ /fancyindex/ {
alias /etc/nginx/modules/fancyindex/;
}
#fixup favicon.ico
location /favicon.ico {
alias /etc/nginx/modules/fancyindex/meta/favicon.ico;
}
location =/fancyindex/fancyindex.conf {
deny all;
}
location =/fancyindex/README.md {
deny all;
}
location =passwd {
deny all;
}
#aaa.php.txt aaa.php.conf
location ~ \.php\..*$ {
deny all;
}
location ~ /cgi {
deny all;
}
location ~ /\. {
deny all;
}
}