下载地址:https://github.com/filebrowser/filebrowser/releases
下载地址中作者提供了各平台编译好的二进制文件,根据自己的平台下载解压即可,无需自行编译。
##下载File Browser
wget https://github.com/filebrowser/filebrowser/releases/download/v2.24.1/linux-amd64-filebrowser.tar.gz
#解压
tar -zxvf linux-amd64-filebrowser.tar.gz
#移动位置
mv filebrowser /usr/local/bin
创建配置文件
File Browser支持json, toml, yaml, yml格式的配置文件,以json格式为例,命令如下:
#先创建一个目录用来存放数据库和配置文件
mkdir /etc/filebrowser/
#新建配置文件
nano /etc/filebrowser/config.json
复制下面的内容保存到/etc/filebrowser/config.json
{
"address":"0.0.0.0",
"database":"/etc/filebrowser/filebrowser.db",
"log":"/var/log/filebrowser.log",
"port":8080,
"root":"/home",
"username":"admin"
}
上面参数含义为如下,请根据自身情况修改。
• address:监听地址
• database:数据库地址
• log:日志文件路径
• port:需要监听的端口
• root:需要读取哪个目录下的文件
• username:用户名
运行File Browser
参数-c
是指定File Browser配置文件路径,请根据自身情况填写路径,命令如下:
#常规运行
filebrowser -c /etc/filebrowser/config.json
#如果需要保持在后台运行,执行
nohup filebrowser -c /etc/filebrowser/config.json &
守护进程
nano /etc/systemd/system/filebrowser.service
[Unit]
Description=File browser
After=network.target
[Service]
ExecStart=/usr/local/bin/filebrowser -c /etc/filebrowser/config.json
[Install]
WantedBy=multi-user.target
systemctl enable filebrowser.service
Nginx 反代配置优化,只列出关键部分:
注意我这里是 root 权限运行的 nginx,请根据实际情况修改。
server
server {
#其他内容
#允许大文件上传
client_max_body_size 0;
}
location
location ~* / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
#大文件上传参数优化
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#禁止服务端、客户端缓存策略
add_header Last-Modified $date_gmt;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;
}
扩展
创建配置数据库:
filebrowser -d /etc/filebrowser.db config init
设置监听地址:
filebrowser -d /etc/filebrowser.db config set --address 0.0.0.0
设置监听端口:
filebrowser -d /etc/filebrowser.db config set --port 8080
设置语言环境:
filebrowser -d /etc/filebrowser.db config set --locale zh-cn
设置日志位置:
filebrowser -d /etc/filebrowser.db config set --log /var/log/filebrowser.log
添加一个用户:
filebrowser -d /etc/filebrowser.db users add root password --perm.admin
其中的root和password分别是用户名和密码,根据自己的需求更改。
有关更多配置的选项,可以参考官方文档:https://docs.filebrowser.xyz/