Skip to content

Instantly share code, notes, and snippets.

@kindy
Created April 25, 2018 07:52
Show Gist options
  • Save kindy/f7042187fc15d28601b27734a1a1bc5d to your computer and use it in GitHub Desktop.
Save kindy/f7042187fc15d28601b27734a1a1bc5d to your computer and use it in GitHub Desktop.
Simple File Server(upload) / 简易文件服务器(支持上传)

Simple File Server(upload) / 简易文件服务器(支持上传)

一般文件上传都会使用 Form 形式, 其实如果只是为了做一个简单的文件服务的话,那么可以简化许多。

Nginx 默认提供了文件访问服务,使用 autoindex 可以提供文件list 功能; 对于文件上传,使用 WebDAV模块可以极大简化上传的实现及用法。

Nginx 配置

server {
  listen      80;

  root /main/ss_root;

  location ~ ^/files/ {
    autoindex on;
    autoindex_exact_size off;

    client_body_in_file_only on;
    client_body_temp_path /main/ss_body_temp;
  
    dav_methods PUT;
    create_full_put_path  on;
    dav_access  group:rw  all:r;
  }

}

用法

文件的查看和浏览使用浏览器即可

上传

  curl -X PUT -T path/to/local.png http://ip/files/path/on/server.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment