前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >文件服务器搭建 - 基于 Nginx 和 File Browser

文件服务器搭建 - 基于 Nginx 和 File Browser

原创
作者头像
Nujil
修改2023-07-07 11:59:09
6280
修改2023-07-07 11:59:09
举报
文章被收录于专栏:CNotesCNotes

文件服务器搭建 - 基于 Nginx 和 File Browser

VM Details:

这里我是在一台 ESXi 服务器上创建了 Ubuntu 虚机作为文件服务器,配置仅供参考

* ESXi-Host: 192.168.118.25

* 虚机名称:File-Server-50

* 操作系统:Ubuntu-20.04

* 参数配置:CPU:4, Memory:4G, Hard Disk:4T

安装部署方法:

基础网络配置

注意⚠️:安装部署下面的服务需要依赖外网连接,具体所需配置因实际情况而异

Nginx 服务 - 文件只读/下载页面(对外): http://192.168.118.50/

安装Nginx

系统是debian或者ubuntu的可以用以下命令安装:

sudo apt install nginx-extras -y

创建 & 配置 conf 文件:

sudo vim /etc/nginx/conf.d/file_server.conf

代码语言:txt
复制
server {

  listen      80;

  listen      [::]:80;

  server\_name 192.168.118.50; # 自己PC的ip或者服务器的域名 

  charset utf-8; # 避免中文乱码 

  root /home/ubuntu/share; # 存放文件的目录 

  location / { 

    fancyindex on;            # 索引

    fancyindex\_exact\_size off; # 关闭文件大小

    fancyindex\_localtime on;  # 显示文件时间

    fancyindex\_name\_length 255;

    # 美化,也可以注释掉不要

    fancyindex\_header "/Nginx-Fancyindex-Theme-light/header.html";

    fancyindex\_footer "/Nginx-Fancyindex-Theme-light/footer.html";

    fancyindex\_ignore "examplefile.html";

    fancyindex\_ignore "Nginx-Fancyindex-Theme-light";

    fancyindex\_time\_format "%Y-%m-%d %H:%M";

    # 密码,也可以注释掉不用

    # auth\_basic "user login";

    # auth\_basic\_user\_file /etc/nginx/passwd/file\_server;

  }

 

}
美化 - Fancy Index主题

下载Fancy Index主题: https://github.com/Naereen/Nginx-Fancyindex-Theme?login=from_csdn

解压该主题,注意,解压后有2个主题,分别是Nginx-Fancyindex-Theme-light和Nginx-Fancyindex-Theme-dark,选择自己喜欢的一个并上传到root目录,我们这里是/home/admin/(在这里我选择的是Nginx-Fancyindex-Theme-light,如果选择的是Nginx-Fancyindex-Theme-dark,则相应的在上面配置文件中也要修改)

重新加载nginx的配置文件

sudo systemctl restart nginx.service

File Browser 服务 - 文件管理页面(对内): http://192.168.118.50:8080/files/

安装方式参考官网: https://filebrowser.org/installation

页面访问方式

  1. 对外只读/下载页面: http://192.168.118.50/
  2. 对内文件管理页面: http://192.168.118.50:8080/files/

维护

服务器设置了开机自启Nginx 和 File Browser 服务,如果虚机有断电重启服务起不来的情况,需要尝试手动执行下面文件内的命令启动:

代码语言:txt
复制
root@File-Server-50:~# cat /etc/rc.local

#! /bin/bash

nohup filebrowser -r /home/admin/ -a 192.168.118.50

systemctl start nginx.service

如何设置开机自启动:

检查系统目录/lib/systemd/system/rc-local.service,如果没有自己新建,文件内容为(如果文件存在本身是没有Install项的,需要自己添加进去)

代码语言:txt
复制
#### 文件中本身就有的

[Unit]

Description=/etc/rc.local Compatibility

Documentation=man:systemd-rc-local-generator(8)

ConditionFileIsExecutable=/etc/rc.local

After=network.target



[Service]

Type=forking

ExecStart=/etc/rc.local start

TimeoutSec=0

RemainAfterExit=yes

GuessMainPID=no



####  需要自己添加

[Install]

WantedBy=multi-user.target

Alias=rc-local.service

同样etc目录下的文件也需要进行如上修改(有可能已经自动修改),检查/etc/systemd/system/rc-local.service,进行以上修改。

2.创建/etc/rc.local脚本文件,并写入想要运行的脚本程序

(可以先写个示例验证一下)

代码语言:txt
复制
#! /bin/bash

#### 这里在/usr/local里面创建文件夹是想看是否有执行的权限

#### 事实证明是有的

mkdir /usr/local/temp

echo "test auto bootstrap" > /usr/local/temp/1.log

3.给rc.local执行的权限

代码语言:txt
复制
sudo chmod +x /etc/rc.local

4.启用服务

代码语言:txt
复制
sudo systemctl enable rc-local



sudo systemctl start rc-local.service

sudo systemctl status rc-local.service

5.查看效果

可以看到/usr/local/temp文件夹被创建了,1.log文件也被创建了。

验证重启

参考自:

https://blog.csdn.net/littesss/article/details/127998179

https://blog.csdn.net/t624124600/article/details/111085234

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文件服务器搭建 - 基于 Nginx 和 File Browser
    • VM Details:
      • 安装部署方法:
        • 基础网络配置
        • Nginx 服务 - 文件只读/下载页面(对外): http://192.168.118.50/
        • File Browser 服务 - 文件管理页面(对内): http://192.168.118.50:8080/files/
      • 页面访问方式
        • 维护
          • 如何设置开机自启动:
        • 参考自:
        相关产品与服务
        文件存储
        文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档