使用nginx+fancyindex搭建一個帶搜索功能漂亮的目錄瀏覽站點


1.前言:nginx自帶目錄索引,功能簡單、樣式也不好看,而且長文件名還顯示不全,使用fancyindex插件來做索引,配上一個漂亮的主題還有搜索的功能,使界面看起來賞心悅目。

2.軟件版本

web:Nginx 1.14.0
fancy: fancyindex V0.4.3
fancy-theme: fancy v1.1

3.下載並安裝包

yum install gcc gcc-c++ wget ntpdate vim-enhanced autoconf automake openssl-devel pcre-devel unzip
wget http://nginx.org/download/nginx-1.14.0.tar.gz
wget -O fancyindex.zip https://github.com/aperezdc/ngx-fancyindex/archive/v0.4.3.zip
wget -O fancytheme.zip https://github.com/Naereen/Nginx-Fancyindex-Theme/archive/master.zip
tar -zxvf nginx-1.14.0.tar.gz
unzip fancyindex.zip
unzip fancytheme.zip

4.編譯安裝nginx,增加插件模塊

cd nginx-1.14.0
./configure --prefix=/usr/local/nginx --add-module=../ngx-fancyindex-0.4.3/
//確定沒有錯誤后,執行make && make install
make && make install
cp -r /root/Nginx-Fancyindex-Theme-master/fancyindex.conf /usr/local/nginx/conf/
cp -r /root/Nginx-Fancyindex-Theme-master/Nginx-Fancyindex-Theme-dark /usr/local/nginx/html/fancydark         #黑色主題,選擇其中一種即可
cp -r /root/Nginx-Fancyindex-Theme-master/Nginx-Fancyindex-Theme-light /usr/local/nginx/html/fancydark-light  #白色主題

5.修改html文件引用:cd /usr/local/nginx/html/fancydark 【不然無法讀取樣式,可以通過styles.css修改頁面樣式】

6.修改配置文件

vim /usr/local/nginx/conf/nginx.conf

worker_processes 4;

events {
    worker_connections 1024;
}

http {
    include mime.types;
    default_type application/octet-stream;

    sendfile on;
    keepalive_timeout 65;

    server {
        listen 8001;
        server_name localhost;

        location / {
            root html;
            include fancyindex.conf;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }
}

vim /usr/local/nginx/conf/fancyindex.conf

fancyindex on;
fancyindex_localtime on;
fancyindex_exact_size off;
fancyindex_header "/fancydark/header.html";
fancyindex_footer "/fancydark/footer.html";
fancyindex_ignore "fancydark";
fancyindex_name_length 200;

7.驗證配置文件並啟動nginx

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx

8.查看效果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM