Openresty学习(五):nginx作为文件服务器使用

文件上传与下载是web服务器的重要功能。配置nginx文件服务器,支持文件上传和下载功能


官网参考资料:

http://nginx.org/en/docs/http/ngx_http_autoindex_module.html

location / {
    autoindex on;
}


http://nginx.org/en/docs/http/ngx_http_dav_module.html


编译:

需要重新编译openresty/nginx, 打开dav模块,编译参数--with-http_dav_module

配置:

        location /file {
                          root /data/;
                          autoindex_localtime on;
                          autoindex_exact_size off;
                          autoindex_format html;
                          autoindex on;
                 }
        location / {
                root                  /data/file;

                client_body_temp_path /data/client_temp;

                dav_methods PUT DELETE MKCOL COPY MOVE;

                create_full_put_path  on;
                dav_access            group:rw  all:r;

                #limit_except GET {
                #       allow 192.168.1.0/32;
                #       deny  all;
                #}
        }

autoindex_format html | xml | json | jsonp;


测试:

1. 访问文件列表

http://my_ip:port/file/

[
{ "name":"hello_world.txt", "type":"file", "mtime":"Sun, 27 May 2018 00:54:40 GMT", "size":13 },
{ "name":"test2.txt", "type":"file", "mtime":"Sun, 27 May 2018 03:54:04 GMT", "size":12 }
]

[
{ "name":"hello_world.txt", "type":"file", "mtime":"Sun, 27 May 2018 00:54:40 GMT", "size":13 }
]


2. 下载文件

curl -O http://localhost/file/test2.txt

3. 上传文件

curl -T test3.txt http://localhost/

上传后列表:

../
hello_world.txt                                    27-May-2018 08:54      13
test2.txt                                          27-May-2018 11:54      12
test3.txt                                          27-May-2018 13:15       0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浪游东戴河

你就是这个世界的唯一

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值