欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nginx添加ngx-fancyindex模塊的方法

 更新時(shí)間:2018年06月01日 09:07:08   作者:Alliot  
這篇文章主要介紹了Nginx添加ngx-fancyindex模塊的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

為了安全起見,Nginx默認(rèn)是不允許列出整個(gè)目錄的,即當(dāng)訪問一個(gè)不包含首頁(yè)的目錄時(shí)會(huì)返回 403 錯(cuò)誤,當(dāng)我們需要將服務(wù)器某一目錄列出索引以便下載,我們可以使用 autoindex 來(lái)實(shí)現(xiàn),但是 autoindex 模塊生成的索引非常簡(jiǎn)陋,我們可以使用 ngx-fancyindex 代替 autoindex 實(shí)現(xiàn)索引目錄美化。

本文為已安裝 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

第二步

下載對(duì)應(yīng)版本的 Nginx 源碼包: http://nginx.org/download/

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

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

第三步

編譯 Nginx

cd /tmp/nginx-1.8.0 #進(jìn)入源碼目錄 
./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后面的配置要對(duì)應(yīng)第一步的輸出信息,防止不必要的麻煩,–add-module=../ngx-fancyindex-0.4.2 這里根據(jù)你下載解壓后的 ngx-fancyindex 目錄名來(lái)。
  2. 只需要 make,不需要 install.

第四步

重命名舊的 nginx 文件:

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

復(fù)制重新編譯的nginx文件到nginx原來(lái)安裝目錄下:

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

重新啟動(dòng) nginx 服務(wù):

service nginx restart

配置ngx-fancyindex

修改nginx配置文件

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

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

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

重載配置

執(zhí)行

nginx -s reload

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論