一、下载Nginx
首先,确保你的服务器上已经安装了Nginx,使用编译安装,下载最新版Nginx。
wget https://nginx.org/download/nginx-1.25.3.tar.gz
tar -xf nginx-1.25.3.tar.gz
二、安装Fancyindex和Nginx-Fancyindex-Theme模块
# 下载Fancyindex模块
git clone https://github.com/aperezdc/ngx-fancyindex.git
# 下载Nginx-Fancyindex-Theme
git clone https://github.com/Naereen/Nginx-Fancyindex-Theme.git
# 使用/data/package作为文件存在目录
mkdir -p /data/package
cd Nginx-Fancyindex-Theme
cp -a Nginx-Fancyindex-Theme-* /data/package/
编译安装
#如果有报错./configure: error: C compiler cc is not found则执行
yum remove -y gcc
yum install -y gcc gcc-c++
./configure --prefix=/usr/local/nginx/ --add-module=/data/package/ngx-fancyindex
make && make install
[root@cdn nginx-1.25.3]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.25.3
built by gcc 10.3.1 (GCC)
configure arguments: --prefix=/usr/local/nginx/ --add-module=/data/package/ngx-fancyindex
三、配置Nginx
编辑Nginx配置文件,添加Fancyindex相关配置。
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root /data/package/;
fancyindex on;
fancyindex_localtime on;
fancyindex_exact_size off;
# 有两个主题可以选择,可以选择light或者dark
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_ignore "Nginx-Fancyindex-Theme-dark";
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}
启动nginx
/usr/local/nginx/sbin/nginx
四、页面访问