主頁 > 知識庫 > Nginx添加ngx-fancyindex模塊的方法

Nginx添加ngx-fancyindex模塊的方法

熱門標簽:地圖標注員怎么去做 威海人工智能電銷機器人系統(tǒng) 機器人電銷有什么用 好看的地圖標注圖標下載 貴州全自動外呼系統(tǒng)廠家 上海電銷卡外呼系統(tǒng)廠家 百度地圖標注備注 福州外呼系統(tǒng)中間件 德州外呼系統(tǒng)排名

為了安全起見,Nginx默認是不允許列出整個目錄的,即當訪問一個不包含首頁的目錄時會返回 403 錯誤,當我們需要將服務器某一目錄列出索引以便下載,我們可以使用 autoindex 來實現,但是 autoindex 模塊生成的索引非常簡陋,我們可以使用 ngx-fancyindex 代替 autoindex 實現索引目錄美化。

本文為已安裝 Nginx 環(huán)境下的操作。

安裝ngx-fancyindex

第一步

查看已安裝的 Nginx 版本與模塊信息:

nginx -V

輸出信息類似于:

nginx version: nginx/1.8.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx

第二步

下載對應版本的 Nginx 源碼包: http://nginx.org/download/

下載最新版本的 ngx-fancyindex 源碼包: https://github.com/aperezdc/ngx-fancyindex/releases

上傳至服務器并解壓,這里我們上傳到/tmp目錄。

第三步

編譯 Nginx

cd /tmp/nginx-1.8.0 #進入源碼目錄 
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx --add-module=../ngx-fancyindex-0.4.2
make  #編譯

特別注意:

  1. ./configure后面的配置要對應第一步的輸出信息,防止不必要的麻煩,–add-module=../ngx-fancyindex-0.4.2 這里根據你下載解壓后的 ngx-fancyindex 目錄名來。
  2. 只需要 make,不需要 install.

第四步

重命名舊的 nginx 文件:

mv /usr/local/nginx /usr/local/nginx.bak

復制重新編譯的nginx文件到nginx原來安裝目錄下:

cp ./objs/nginx /usr/local/nginx/sbin/

重新啟動 nginx 服務:

service nginx restart

配置ngx-fancyindex

修改nginx配置文件

location /path/ #指定~/path目錄開啟自動列目錄
{
 alias /alliot/path/; #虛擬目錄/alliot/path/開啟自動列目錄
 root /path/;  #實際目錄/path/開啟自動列目錄 與alias二選一
 fancyindex on;  #開啟nginx目錄瀏覽功能 
 fancyindex_exact_size off; #文件大小從KB開始顯示 
 fancyindex_localtime on; #顯示文件修改時間為服務器本地時間 
 fancyindex_footer "footer.html"; #設置footer為當前目錄下的footer.html
 fancyindex_ignore "footer.html"; #設置不列出當前目錄下的footer.html
}

上面 alias 與 root 的區(qū)別在于, alias 指定的是當前目錄,而 root 指定的是根目錄,一般情況下,建議在 “l(fā)ocation /” 中通過root命令來配置根目錄。

更多配置見 https://github.com/aperezdc/ngx-fancyindex

重載配置

執(zhí)行

nginx -s reload

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

標簽:撫州 南陽 葫蘆島 白城 泉州 南陽 邵陽 岳陽

巨人網絡通訊聲明:本文標題《Nginx添加ngx-fancyindex模塊的方法》,本文關鍵詞  Nginx,添加,ngx-fancyindex,模塊,;如發(fā)現本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Nginx添加ngx-fancyindex模塊的方法》相關的同類信息!
  • 本頁收集關于Nginx添加ngx-fancyindex模塊的方法的相關信息資訊供網民參考!
  • 推薦文章