【caddy】Ubuntu 中使用 Caddy Web 服务器 和 filemanager 插件 搭建 文件服务器

本文介绍如何使用Caddy Web服务器及filemanager插件快速搭建文件管理系统,支持文件上传、下载、预览等功能,并介绍了配置步骤及注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不管在公司还是自己家中,搭建一套内网文件系统还是可以带来很大便利的。之前使用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进行简单配置即可搭建界面友好的文件服务器。
注意:由于作者有重大更新(此时 2019-01-14,已暂时下架最新插件),特别在这里附上一个本人之前下载的版本:v0.11.1(点击下载) 希望会对大家有帮助。。。

filemanager插件文档地址

基本特性

  • 可以下载;

  • 可以上传;

  • 可以删除;

  • 可以重命名;

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

  • 可以预览视频和图片;

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

三、安装、配置、运行

1、安装

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

5、注意

filemanager 可以以插件形式按照上文方法搭建文件服务器;
filemanager 也可以以独立程序的形式提供文件服务器的服务;
可以到 filemanager 官方网站下载相关程序,以及查看相关文档;
官网地址:filemanager
Github地址:github


—— 2018-09-17 ——

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值