ubuntu18.04利用Caddy插件filemanager搭建文件服务器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/TMT123421/article/details/82740660

不管在公司还是自己家中,搭建一套内网文件系统还是可以带来很大便利的。之前使用httpd、nginx等web服务器都可以轻松做到,不过现在,Caddy + filemanager插件可以做得更好。

一、Caddy简介

Caddy是一个go语言开发的web服务器,以开箱即用、自动支持HTTPS著称。

官网有句话是:“Other web servers were designed for the Web, but Caddy was designed for humans, with today’s Web in mind.”

Caddy官网地址

基本特性

  • 默认支持HTTP/2,使用 Let’s Encrypt 可以全自动变成全站HTTPS,无需任何配置(可配置自己CA证书);

  • 多核支持;

  • 完全支持IPv6;

  • 功能插件化,可以自己轻松开发插件;

  • 支持WebSockets;

  • 支持自动把md转成 HTML;

  • 简单的log日志配置;

  • 二进制部署,无依赖;

  • 反向代理,管理多个站点;

  • 更多详细特性描述,请移步:Caddy Web Server Features

二、filemanager插件

filemanager是基于浏览器中间件的扩展。它提供了指定目录的文件管理接口,可用于上传、删除、预览和重命名该目录中的文件。配合caddy进行简单配置即可搭建界面友好的文件服务器。

filemanager文档地址

基本特性

  • 可以下载;

  • 可以上传;

  • 可以删除;

  • 可以重命名;

  • 可以进行用户权限管理;

  • 可以预览视频和图片;

  • 还可以针对大文件进行一些timeout设置;

三、安装、配置、运行

1、安装

  • 官网下载包含fliemanager的二进制文件

    download_caddy

  • 解压到指定目录

    tar_zxvf_caddy

  • 保留二进制程序caddy,其余项移动到新建的 bak 文件夹

2、配置

  • 创建专用文件和文件夹

    files - 文件服务器根目录;

    www - Caddy的web文件存放目录;

    log - Caddy运行日志;

    filemanager.db - 存储设置的数据库的路径;

    Caddyfile - Caddy配置文件;

    caddy_tree

  • caddy配置文件简介

    
    # 基本格式如下:
    
    mysite.com {
      root /www/mysite.com
      gzip
      log ../access.log
    }
    
    mysite2.com {
      root /www/sub.mysite.com
      gzip
      log ../access.log
    }
    
    localhost:8080, https://site.com, http://mysite.com {
      ...
    }

    内容太多,详见:Caddy在线文档

  • filemanager配置文件详解

    filemanager [url] [scope] {
      database            path
      no_auth
      recaptcha_key       key
      recaptcha_secret    secret
      alternative_recaptcha
      locale              [en|jp|...]
      allow_commands      [true|false]
      allow_edit          [true|false]
      allow_new           [true|false]
      allow_publish       [true|false]
      commands            cmd1 cmd2...
      css                 path
    }
    • url is the URL path where you will access File Browser. Defaults to /.
    • database is the path for the database where the settings will be stored.
    • no_auth disables the authentication. This should be enabled if you will use another login method (such as basicauth).
    • recaptcha_key and recaptcha_secret are the Site Key and Secret Key used to enable ReCaptcha on login.
    • alternative_recaptcha replaces https://www.google.com to https://recaptcha.net in ReCaptcha handling and serving, especially useful in China. See gh-filebrowser#366 for details. Defaults to false.

    The following options are mere defaults: they will only be used as the default options for new users. After creating a user, its settings should be changed through the Web UI. Although, when using no_auth option, the following will define the user permissions.

    • scope is the path, relative or absolute, to the directory you want to browse in. Defaults to ./.
    • locale is the default language for new users.
      • de - German
      • en - English
      • es - Spanish
      • fr - French
      • it - Italian
      • ja - Japanese
      • pl - Polish
      • pt - Portuguese
      • pt-br - Portuguese (Brasil)
      • ru - Romanian
      • zh-cn - Chinese (Simplified)
      • zh-tw - Chinese (Traditional)
    • allow_commands is the default value for allow commands option.
    • allow_edit is the default value for allow edit option.
    • allow_new is the default value for allow new option.
    • allow_publish is the default value for allow publish option.
    • commands are the default available commands.
    • css is the path for a file with a custom stylesheet.
  • 我的配置文件

    
    # cat Caddyfile
    
    192.168.0.190:2015 { 
    log /home/ubuntu/work/caddy/log/caddy.log
    filemanager / ./files {
        database        /home/ubuntu/work/caddy/filemanager.db
        show            /home/ubuntu/work/caddy/files
        #no_auth
        locale          zh-cn
        allow_new       true
        allow_edit      false
        allow_commands  true
        allow_publish   true
    }
    }

3、运行

$ ./caddy -conf Caddyfile
Activating privacy features... done.
http://192.168.0.190:2015
WARNING: File descriptor limit 1024 is too low for production servers. At least 8192 is recommended. Fix with "ulimit -n 8192".

4、访问

  • 登陆(默认账号:admin 默认密码:admin)

    caddy_login

  • 主界面

    • 可以预览图片视频;
    • 可以执行预设命令;
    • 可以通过工具栏执行上传、下载、移动、复制、分享、删除、重命名、新建、查看详细信息等操作;
    • 可以通过设置菜单进行语言设置、修改密码、样式设置、命令选择、用户管理、用户权限设置等操作;
    • 完美适配移动设备访问;

    caddy_index
    caddy_pic_browse
    caddy_video_browse


—— 2018-09-17 ——

猜你喜欢

转载自blog.csdn.net/TMT123421/article/details/82740660