iis服务器助手广告广告
返回顶部
首页 > 资讯 > 服务器 >如何进行Nginx静态文件服务器搭建及autoindex模块解析
  • 156
分享到

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

2023-06-28 17:06:00 156人浏览 薄情痞子
摘要

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

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

ngx_http_autoindex_module

ngx_Http_autoindex_module模块处理以斜杠字符(’/’)结尾的请求,并生成目录列表。

当ngx_http_index_module模块找不到index.html文件时,

通常会将请求传递给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, locationThis 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 -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二进制文件,用新生成的二进制文件做替换,在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模块解析了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注编程网服务器频道。

--结束END--

本文标题: 如何进行Nginx静态文件服务器搭建及autoindex模块解析

本文链接: https://www.lsjlt.com/news/320925.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作