溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何進(jìn)行Nginx靜態(tài)文件服務(wù)器搭建及autoindex模塊解析

發(fā)布時(shí)間:2022-01-21 10:07:42 來源:億速云 閱讀:373 作者:柒染 欄目:開發(fā)技術(shù)

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)如何進(jìn)行Nginx靜態(tài)文件服務(wù)器搭建及autoindex模塊解析,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

ngx_http_autoindex_module

ngx_http_autoindex_module模塊處理以斜杠字符(’/’)結(jié)尾的請求,并生成目錄列表。

當(dāng)ngx_http_index_module模塊找不到index.html文件時(shí),

通常會將請求傳遞給ngx_http_autoindex_module模塊。

配置樣例:

location / {root /home/map/www/; #指定目錄所在路徑autoindex on; # 打開目錄瀏覽功能autoindex_exact_size off;# 以可讀的方式顯示文件大小,單位為 KB、MB 或者 GB,autoindex_format為html格式時(shí)有效autoindex_localtime on; # 以服務(wù)器的文件時(shí)間作為顯示的時(shí)間,autoindex_format為html格式時(shí)有效#autoindex_format html; # 以網(wǎng)頁的風(fēng)格展示目錄內(nèi)容。該屬性在1.7.9及以上適用charset utf-8,gbk; # 展示中文文件名}


autoindex

開啟或者關(guān)閉列出目錄中文件的功能

Syntax: autoindex on | off;Default: autoindex off;Context: http, server, location


autoindex_exact_size

對于HTML格式,指定是否應(yīng)在目錄列表中輸出精確的文件大小,或者將其舍入為千字節(jié),兆字節(jié)和千兆字節(jié)

Syntax: autoindex_exact_size on | off;Default: autoindex_exact_size on;Context: http, server, location


autoindex_localtime

對于HTML格式,指定是否應(yīng)該在本地時(shí)區(qū)或UTC中輸出目錄列表中的時(shí)間。

Syntax: autoindex_localtime on | off;Default: autoindex_localtime off;Context: http, server, location


autoindex_format

設(shè)置目錄列表的格式。

當(dāng)使用JSONP格式時(shí),使用callback請求參數(shù)設(shè)置回調(diào)函數(shù)的名稱。如果參數(shù)丟失或具有空值,則使用JSON格式。XML輸出可以使用ngx_http_xslt_module模塊進(jìn)行轉(zhuǎn)換。Syntax: autoindex_format html | xml | json | jsonp;Default: autoindex_format html;Context: http, server, locationThis directive appeared in version 1.7.9.


Nginx Fancy Index module

在實(shí)際體驗(yàn)中ngx_http_autoindex_module模塊顯示出的界面有點(diǎn)不好看,所以我們可以采用第三的Nginx Fancy Index module模塊,該模塊提供動態(tài)加載,當(dāng)然也可以編譯,這里采用編譯安裝,替換原有的nginx二進(jìn)制文件。

如果是動態(tài)加載模塊需要在events塊上面添加:
load_module “modules/ngx_http_fancyindex_module.so”;

# 查看原有的nginx編譯模塊[root@localhost sbin]# ./nginx -Vnginx version: nginx/1.14.2built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)configure arguments: --prefix=/usr/local/nginx下載Nginx Fancy Index module 源碼包:https://github.com/aperezdc/ngx-fancyindex/archive/v0.4.4.tar.gz# 編譯./configure --prefix=/usr/local/nginx --add-module=/root/nginx-src/ngx-fancyindex-0.4.4make#不能make insatll備份原本的nginx二進(jìn)制文件,用新生成的二進(jìn)制文件做替換,在nginx.conf中添加一下內(nèi)容, fancyindex就已經(jīng)啟用完成


編輯nginx.conf

location / {#include /usr/local/nginx/html/Nginx-Fancyindex-Theme/fancyindex.conf;root django-document/;#autoindex on;#autoindex_exact_size off;fancyindex on; #開啟nginx目錄瀏覽功能fancyindex_exact_size off; #文件大小從KB開始顯示fancyindex_localtime on; #顯示文件修改時(shí)間為服務(wù)器本地時(shí)間#set $limit_rate 1k;#root html;#index index.html index.htm;}


此時(shí)主題還是略丑,可以下載主題包 git clone https://github.com/lanffy/Nginx-Fancyindex-Theme.git

復(fù)制Nginx-Fancyindex-Theme文件到root 文件夾下,在nginx.conf中引入主題包,美化完畢。

location / {include /usr/local/nginx/html/Nginx-Fancyindex-Theme/fancyindex.conf;root django-document/;autoindex on;autoindex_exact_size off;}

上述就是小編為大家分享的如何進(jìn)行Nginx靜態(tài)文件服務(wù)器搭建及autoindex模塊解析了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI