温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何进行Nginx静态文件服务器搭建及怎么解析autoindex模块

发布时间:2021-10-29 09:26:15 来源:亿速云 阅读:265 作者:柒染 栏目:软件技术

这期内容当中小编将会给大家带来有关如何进行Nginx静态文件服务器搭建及怎么解析autoindex模块,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

ngx_http_autoindex_module模块处理以斜杠字符('/')结尾的请求,并生成目录列表。当ngx_http_index_module模块找不到index.html文件时,通常会将请求传递给ngx_http_autoindex_module模块。ngx_http_autoindex_module

配置样例:

location / {
root /home/map/www/; #指定目录所在路径
autoindex on; # 打开目录浏览功能
autoindex_exact_size off;# 以可读的方式显示文件大小,单位为 KB、MB 或者 GB,autoindex_format为html格式时有效
autoindex_localtime on; # 以服务器的文件时间作为显示的时间,autoindex_format为html格式时有效
#autoindex_format html; # 以网页的风格展示目录内容。该属性在1.7.9及以上适用
charset utf-8,gbk; # 展示中文文件名
}

autoindex

开启或者关闭列出目录中文件的功能

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

autoindex_exact_size

对于HTML格式,指定是否应在目录列表中输出精确的文件大小,或者将其舍入为千字节,兆字节和千兆字节

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

autoindex_localtime

对于HTML格式,指定是否应该在本地时区或UTC中输出目录列表中的时间。

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

autoindex_format

设置目录列表的格式。

当使用JSONP格式时,使用callback请求参数设置回调函数的名称。如果参数丢失或具有空值,则使用JSON格式。
XML输出可以使用ngx_http_xslt_module模块进行转换。
Syntax: autoindex_format html | xml | json | jsonp;
Default: autoindex_format html;
Context: http, server, location
This directive appeared in version 1.7.9.

Nginx Fancy Index module

在实际体验中ngx_http_autoindex_module模块显示出的界面有点不好看,所以我们可以采用第三的Nginx Fancy Index module模块,该模块提供动态加载,当然也可以编译,这里采用编译安装,替换原有的nginx二进制文件。

如果是动态加载模块需要在events块上面添加:
load_module "modules/ngx_http_fancyindex_module.so";

# 查看原有的nginx编译模块
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.14.2
built 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.4
make
#不能make insatll
备份原本的nginx二进制文件,用新生成的二进制文件做替换,在nginx.conf中添加一下内容, fancyindex就已经启用完成

编辑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; #显示文件修改时间为服务器本地时间
#set $limit_rate 1k;
#root html;
#index index.html index.htm;
}

此时主题还是略丑,可以下载主题包 git clone https://github.com/lanffy/Nginx-Fancyindex-Theme.git

复制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;
}

上述就是小编为大家分享的如何进行Nginx静态文件服务器搭建及怎么解析autoindex模块了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI