说明:比较推荐,通过Alist上传的文件可以在系统中正常查看,在系统内创建的文件也会显示在Alist中,在Alist中无法看到磁盘使用情况,可以挂载其他网盘

1 安装alist

1.1 下载alist

wget https://github.com/alist-org/alist/releases/latest/download/alist-linux-amd64.tar.gz
#https://github.com/alist-org/alist/releases 查看最新版本
tar -zxvf alist-linux-amd64.tar.gz

1.2 设置安装路径

#必须建立alist目录,因为移动过去的alist只是一个文件,运行alist会在当前目录生成文件
mkdir -p /app/alist
mv alist  /app/alist
chmod +x /app/alist/alist

1.3 启动程序

一定要在/app/alist目录下启动程序,这样alist的data目录才会在/app/alist下生成。

cd /app/alist
./alist admin
./alist server

当你看到 {start server@0.0.0.0:5244} 的输出,之后没有报错,说明操作成功。 第一次运行时会输出初始密码。程序默认监听 5244 端口。 现在打开 {http://ip:5244} 可以看到登录页面

如果忘记密码可以用以下命令重置密码,修改密码之前要先停止alist程序

#./alist admin random

1.4 守护进程

创建用户和组

groupadd --system alist
useradd --system \
    --gid alist \
    --create-home \
    --shell /usr/sbin/nologin \
    --comment "AList" \
    alist

#--system 创建系统用户,系统账户的用户id一般是小于一千的;其实就是给UID一个确定的代号,它不能用于登录,一般是给程序来使用;
#--gid 加入到指定组
#--create-home 其实这是一个临时开关,表示如果不存在用户主目录,则生成用户主目录(/home/[用户名])
#--shell /usr/sbin/nologin 拒绝用户登录
#--comment 加上备注文字
#alist 要创建的组名和用户名

编辑 /etc/systemd/system/alist.service

nano /etc/systemd/system/alist.service

添加如下内容

[Unit]
Description=alist
After=network.target

[Service]
User=alist
Group=alist
Type=simple
WorkingDirectory=/app/alist
ExecStart=/app/alist/alist server
Restart=on-failure

[Install]
WantedBy=multi-user.target

设置权限

chown -R alist:alist /app/alist
#本地存储权限
chown -R alist:alist /html/网盘

开机自启

systemctl daemon-reload
systemctl enable alist

启动

systemctl start alist

查看状态

systemctl status alist

1.5 修改端口

nano /app/alist/data/config.json

重启程序

systemctl restart alist
systemctl status alist

2 配置反代

2.1 申请证书

#nginx -s stop
systemctl stop nginx
apt-get install socat curl cron
curl https://get.acme.sh | sh
#通配符证书申请
mkdir /etc/nginx/ssl/
acme.sh --issue --standalone -d kkiikk.top -d www.kkiikk.top -k ec-256
acme.sh --installcert -d kkiikk.top -d www.kkiikk.top --fullchain-file /etc/nginx/ssl/kkiikk.top.crt --key-file /etc/nginx/ssl/kkiikk.top.key --ecc
#普通证书申请
#~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
#~/.acme.sh/acme.sh --issue -d www.kkiikk.top --standalone -k ec-256 --force --test
#rm -rf ~/.acme.sh/www.kkiikk.top_ecc
#以上是测试
#~/.acme.sh/acme.sh --issue -d www.kkiikk.top --standalone -k ec-256 --force
#mkdir /etc/nginx/ssl/
#~/.acme.sh/acme.sh --installcert -d www.kkiikk.top --fullchainpath /etc/nginx/ssl/www.kkiikk.top.crt --keypath /etc/nginx/ssl/www.kkiikk.top.key --ecc --force

2.2 配置nginx

nginx.conf配置

nano /etc/nginx/conf/nginx.conf 
#nano /etc/nginx/nginx.conf

编辑nginx.conf

user  root;
worker_processes  auto;
error_log  /etc/nginx/error.log warn;
pid        /run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/conf/mime.types; #注意路径,必须写,否则可能造成css无法加载
    #include       /etc/nginx/mime.types; #注意路径,必须写,否则可能造成css无法加载
    default_type  application/octet-stream;
    log_format  main  '\$remote_addr - \$remote_user [\$time_local] "\$request" '
                      '\$status \$body_bytes_sent "\$http_referer" '
                      '"\$http_user_agent" "\$http_x_forwarded_for"';
    access_log /etc/nginx/access.log main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  120;
    client_max_body_size 20m;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}

www.conf配置

nano /etc/nginx/conf.d/www.conf

编辑www.conf

server {
        listen 443 ssl;
        listen [::]:443 ssl; #没有ipv6的话要注释掉这行
        ssl_certificate       /etc/nginx/ssl/www.kkiikk.top.crt;
        ssl_certificate_key   /etc/nginx/ssl/www.kkiikk.top.key;
        ssl_protocols         TLSv1.3;
        ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
        server_name www.kkiikk.top;
        #index index.html index.htm;
        #root  /html;
        #error_page 400 = /400.html;

        location / {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Range $http_range;
                proxy_set_header If-Range $http_if_range;
                proxy_redirect off;
                proxy_pass http://127.0.0.1:5244;
                # the max size of file to upload
                client_max_body_size 20000m;
                }

        # Config for 0-RTT in TLSv1.3
        ssl_early_data on;
        ssl_stapling on;
        ssl_stapling_verify on;
        proxy_set_header Early-Data $ssl_early_data;
        add_header Strict-Transport-Security "max-age=31536000";

}

server {
        listen 80;
        listen [::]:80;   #没有ipv6的话要注释掉这行
        server_name www.kkiikk.top;
        return 301 https://www.kkiikk.top$request_uri;
}

server {
        listen 80;
        listen [::]:80;   #没有ipv6的话要注释掉这行
        server_name kkiikk.top;
        return 301 https://www.kkiikk.top$request_uri;
}

重启nginx

systemctl restart nginx

关闭允许挂载
将绝对路径填写到根文件夹路径下面

3 美化及显示磁盘容量

3.1 alist美化设置

在Alist根目录中新建本地磁盘空间.txt文件
在'设置'-'全局'-'自定义内容'内输入以下内容,将xhttp.open后面修改为TXT的下载地址

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!--以下是禁止缓存,否则磁盘容量不会及时更新-->
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

    <!--1.延迟加载,以下内容都要放到延迟加载内-->
    <div id="customize" style="display: none;">  

        <!--2.显示txt内容-->
          <div id="content" style="text-align: center ; "></div>
        
        <!--3.隐藏版权、管理,移除搜索栏中的键盘图标-->
        <style>
            /*隐藏版权*/
            .footer span,.footer a:nth-of-type(1){
                display:none;
            }

            /*隐藏管理字眼*/
            .footer span,.footer a:nth-of-type(2){
                display:none;
            }
            /*移除搜索栏中的键盘图*/
            .hope-stack.hope-c-dhzjXW.hope-c-PJLV.hope-c-PJLV-ihYBJPK-css {
                display: none !important;
            }
        </style>

        <!-- 4.增加底部文字 -->
        <div style="text-align: center ; ">
        <p align="center">
        <a target="_blank" href="https://alist.nn.ci/zh/" > © Powered by AList</a>
        <span>|</span>
        <a target="_blank" href="/@manage" >管理</a>
        </p>
        </div>
        </div>

<!--下面是配套的JS-->

<!--1.延迟加载配套使用JS-->
<script>
    let interval = setInterval(() => {
        if (document.querySelector(".footer")) {
            document.querySelector("#customize").style.display = "";
            clearInterval(interval);
        }
    }, 200);
</script>

<!--2.显示txt内容配套使用JS-->
  <script>
    // 创建 XMLHttpRequest 对象
    var xhttp = new XMLHttpRequest();
    
    // 设置请求方式和文件路径,注意此处的网址为TXT文件的下载地址
    xhttp.open("GET", "https://www.网址.com/xx.txt", true);
    
    // 定义请求完成时的回调函数
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        // 将读取的文本内容存储到变量中
        var text = this.responseText;
        
        // 将文本内容插入到 HTML 页面中

        document.getElementById("content").innerHTML = text;
      }
    };
    
    // 发送请求
    xhttp.send();
  </script>
</head>

3.2 显示磁盘容量设置

3.2.1 创建sh文件

nano /app/alist/显示磁盘剩余空间.sh

输入以下内容

#!/bin/bash
all=$(df -h | grep -w /dev/vda1 | awk '{ print $2 }')     #注意将/dev/vda1修改为当前磁盘的路径 -w为完全匹配,避免返回多个结果
free=$(df -h | grep -w /dev/vda1 | awk '{ print $4 }')    #注意将/dev/vda1修改为当前磁盘的路径 -w为完全匹配,避免返回多个结果
if [ ${free}x != $(awk '{print $2}' /html/网盘/本地磁盘空间.txt)x ]
then
    sed -i "1c 本地磁盘可用空间: ${free} / ${all}" /html/网盘/本地磁盘空间.txt            #此处是前面建立的存储磁盘容量信息的TXT文件的路径
fi

给与权限

chmod +x /app/alist/显示磁盘剩余空间.sh

3.2.2 设置定时器

1、创建服务

nano /etc/systemd/system/checkspace.service

写入以下内容

[Unit]
Description=Check Space
After=network.target

[Service]
Type=simple
ExecStart=/app/alist/显示磁盘剩余空间.sh

2、创建定时器

nano /etc/systemd/system/checkspace.timer

输入以下内容
注意:OnUnitActiveSec的单位为秒

[Unit]
Description=CheckSpaceTimer

[Timer]
OnBootSec=1
OnUnitActiveSec=20
Unit=checkspace.service

[Install]
WantedBy=multi-user.target

3、将定时器加入自启动

systemctl daemon-reload
systemctl enable checkspace.timer
systemctl start checkspace.timer

可以在设置-全局-隐藏文件中加入/\/本地磁盘空间.txt/i来隐藏TXT文件

可以在设置-源信息-隐藏中加入^文件夹名称$来隐藏文件夹,在用户中关闭可以看到隐藏选项。如果是将^文件夹名称$直接复制过去的话,需要回车,否则可能不生效。

4 安装epub.js和pdf.js

4.1 安装epub.js

4.1.1 在alist文件夹下创建epub文件夹

mkdir /app/alist/epub_js
cd /app/alist/epub_js

4.1.2 下载jszip.min.jsepub.min.jsexamples.cssspreads.html

wget https://cdnjs.cloudflare.com/ajax/libs/jszip/3.5.0/jszip.min.js
wget https://github.com/futurepress/epub.js/releases/download/v0.3.88/epub.min.js
wget https://raw.githubusercontent.com/futurepress/epub.js/master/examples/examples.css
wget https://raw.githubusercontent.com/futurepress/epub.js/master/examples/spreads.html

4.1.3 修改spreads.html文件

nano spreads.html

第一部分

找到下面内容:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js"></script>
  <script src="../dist/epub.js"></script>

  <link rel="stylesheet" type="text/css" href="examples.css">

修改为:

<script src="./jszip.min.js"></script>
  <script src="./epub.min.js"></script>
  <link rel="stylesheet" type="text/css" href="examples.css">

第二部分

找到下面的内容:

var params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
var url = params && params.get("url") && decodeURIComponent(params.get("url"));
var currentSectionIndex = (params && params.get("loc")) ? params.get("loc") : undefined;
var book = ePub(url || "https://s3.amazonaws.com/moby-dick/moby-dick.epub");

修改为:

var params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
var currentURL = window.location.href;
var urlPrefix = "https://网址.com/epub_js/spreads.html?url=";
var url = currentURL.substring(urlPrefix.length);
var currentSectionIndex = (params && params.get("loc")) ? params.get("loc") : undefined;
let blob = fetch(url).then((res) => res.blob());
var book = ePub(blob.then((blob) => blob.arrayBuffer()), {
        restore: true,
        reload: true,
        spreads: true
});

4.1.4 修改epub页面大小

修改spreads.html文件

nano spreads.html

找到

height: 600,

修改为

height: "100%",

修改examples.css文件

nano examples.css

修改#viewer.spreads内的内容

width: 90%;
height: 90%;

4.1.5 设置反代

将如下内容添加到nginx的conf

root /app/alist;
location /epub_js/ {}

重启nginx

systemctl restart nginx

4.1.6 修改AList预览设置

在原预览设置的json文件内添加如下键值对,注意修改网址.com为你自己的AList域名,注意是https还是http。

"epub": {
        "epub.js":"https://网址.com/epub_js/spreads.html?url=$url"
    },

4.2 安装pdf.js

4.2.1 建立pdf文件夹

mkdir /app/alist/pdf_js
cd /app/alist/pdf_js

4.2.2 下载

wget https://github.com/mozilla/pdf.js/releases/download/v3.9.179/pdfjs-3.9.179-dist.zip
unzip pdfjs*.zip
rm -rf pdfjs*

4.2.3 设置反代

nano /etc/nginx/conf.d/www.conf

加入以下内容:

root /app/alist;
        location /pdf_js/ {}

重启nginx

systemctl restart nginx

4.2.4 测试pdf.js

https://自己网站的网址.com/pdf_js/web/viewer.html

4.2.5 修改AList预览设置

在原预览设置的json文件内添加如下键值对,注意修改网址.com为你自己的AList域名,注意是https还是http。

"pdf": {
        "PDF.js":"https://网址.com/pdf_js/web/viewer.html?file=$e_url"
    },
最后修改:2025 年 03 月 09 日
如果觉得我的文章对你有用,请随意赞赏