zoukankan      html  css  js  c++  java
  • ngx_http_autoindex_module模块说明 配置文件下载服务。

    配置文件下载服务。

    启用或禁用目录列表

    Syntax:    autoindex on | off;
    Default:    autoindex off;
    Context:    http, server, location
    #自动文件索引功能,默为off

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

    Syntax:    autoindex_exact_size on | off;
    Default:    autoindex_exact_size on;
    Context:    http, server, location
    #计算文件确切大小(单位bytes),off 显示大概大小(单位K、M),默认on

    设置目录列表的格式

    Syntax:    autoindex_format html | xml | json | jsonp;
    Default:    autoindex_format html;
    Context:    http, server, location
    This directive appeared in version 1.7.9.
    #显示索引的页面文件风格,默认html

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

    Syntax:    autoindex_localtime on | off;
    Default:    autoindex_localtime off;
    Context:    http, server, location
    #显示本机时间而非GMT(格林威治)时间,默认off

    配置文件下载服务生产案例

    location /download {
       autoindex on;
       autoindex_exact_size off;
       autoindex_localtime on;
       autoindex_format json;
       limit_rate 100k;
       root /data/nginx/html/pc;
       index index.html;
    }
    mkdir /data/nginx/html/pc/download/

    测试实例

    实验环境

    [root@node1 ~]# uname -r
    3.10.0-957.el7.x86_64
    [root@node1 ~]# cat /etc/redhat-release 
    CentOS Linux release 7.6.1810 (Core) 
    [root@node1 ~]# nginx -V
    nginx version: nginx/1.16.0
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
    built with OpenSSL 1.0.2k-fips  26 Jan 2017
    TLS SNI support enabled
    configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
    
    ip: 10.0.0.101

    实验要求

    在10.0.0.101/down上配置一个可以访问下载的页面

    nginx安装部署位nginx-1.16.0的源码安装,详细见《nginx的安装部署》

    虚拟主机配置

    server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
            
            location /down {
               autoindex on;
               autoindex_exact_size off;
               autoindex_localtime on;
               autoindex_format html;
               limit_rate 100k;
                root   html;
                index  index.html index.htm;
            }
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }

    创建下载目录及文件

    mkdir /usr/local/nginx/html/down
    chown -R www.www /usr/local/nginx/html/down
    cd /usr/local/nginx/html/down 
    touch test{1..3}

    访问测试

    下载测试

    测试完成!!!

    I have a dream so I study hard!!!
  • 相关阅读:
    今天在这里开博客,分享心情与技术
    tp3.2控制器返回时关闭子窗口刷新父页面
    关于iframe与$.load()哪个更好
    javascript的匿名函数的理解(转载学习)
    DOM入门学习笔记
    SQL学习基础笔记
    多线程和套接字入门学习笔记
    网络套接字学习以及聊天程序开发实例
    DOM 讲解结束
    JQuery 基础学习
  • 原文地址:https://www.cnblogs.com/yaokaka/p/13646585.html
Copyright © 2011-2022 走看看