Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build Nginx static file server and parse autoindex module

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, Xiaobian will bring you about how to build Nginx static file server and autoindex module analysis. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.

ngx_http_autoindex_module

The ngx_http_autoindex_module module processes requests that end with a slash ('/') character and generates directory lists.

When ngx_http_index_module cannot find the index.html file,

The request is typically passed to the ngx_http_autoindex_module module.

Sample configuration:

location / {root /home/map/www/; #Specify the path where the directory is located autoindex on; #Turn on directory browsing autoindex_exact_size off;#Display file sizes in KB, MB, or GB in readable format autoindex_localtime on; #Use server file time as display time,autoindex_format html format is valid #autoindex_format html; #Display directory contents in web style. This property applies to charset utf-8,gbk; #show Chinese file name} in 1.7.9 and above

autoindex

Turn on or off the ability to list files in directories

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

autoindex_exact_size

For HTML format, specify whether the exact file size should be output in the directory listing, or rounded to kilobytes, megabytes, and gigabytes

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

autoindex_localtime

For HTML format, specify whether the time in the catalog list should be output in the local time zone or UTC.

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

autoindex_format

Format the catalog list.

When using the JSONP format, use the callback request parameter to set the name of the callback function. If the parameter is missing or has a null value, JSON format is used. XML output can be transformed using the 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

In the actual experience, the interface displayed by the ngx_http_autoindex_module module is a bit ugly, so we can use the third Nginx Fancy Index module, which provides dynamic loading. Of course, it can also be compiled. Here, compile and install to replace the original nginx binary file.

If the module is dynamically loaded, you need to add:

load_module "modules/ngx_http_fancyindex_module.so";

#View original nginx build module [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 Download Nginx Fancy Index module source package: github.com/aperezdc/ngx-fancyindex/archive/v0.4.4.tar.gz# compile./ configure --prefix=/usr/local/nginx --add-module=/root/nginx-src/ngx-fancyindex-0.4.4make#Cannot make insatll Backup the original nginx binary file, replace it with the newly generated binary file, add something to nginx.conf, fancyindex has been enabled

Edit nginx.conf

location / {#include /usr/local/nginx/html/nginx-Fancyindex-Theme/fancyindex.conf;root django-document/;#autoindex on;#autoindex_exact_size off;fancyindex on; #enable nginx directory browsing fancyindex_exact_size off; #file size starts in KB and displays fancyindex_localtime on; #display file modification time as server local time #set $limit_rate 1k;#root html;#index index.html index.htm;}

At this time the theme is still slightly ugly, you can download the theme package git clone https://github.com/lanffy/Nginx-Fancyindex-Theme.git

Copy the Nginx-Fancyindex-Theme file to the root folder, and introduce the theme package into nginx.conf to beautify it.

location / {include /usr/local/nginx/html/Nginx-Fancyindex-Theme/fancyindex.conf;root django-document/;autoindex on;autoindex_exact_size off;} The above is how to build Nginx static file server and autoindex module resolution for everyone. If you happen to have similar doubts, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report