站点图标 谷姐靓号网

【教程】Debian 11安装qbittorrent-nox并设置Nginx反代-imes

Rate this post

源地址https://pa.ci/210.html

因为PT站优先qbittorrent,所以弃用aria2,而在Debian 11上安装qbittorrent,并配置Nginx反代。注意:qbittorrent是自带GUI的,适用于桌面环境;而qbittorrent-nox才是服务器用的,并没有提供桌面GUI,但是提供了网络访问的Web-GUI界面。
安装qbittorrent-nox

没什么好说的,直接执行以下命令就好了,debian 11仓库的qbittorrent-nox是5.25版本,并不算老,各大站点的兼容性也不错。

    apt update
    apt install qbittorrent-nox -y

配置qbittorrent-nox进程守护

不粗暴的使用root执行,而是用户谈执行,这样可以防止万一Web-GUI被爆破了,服务器全被黑了。
1. 添加专属的qbittorrent-nox用户组

    adduser --system --group qbittorrent-nox

2. 将当前用户添加进qbittorrent-nox用户组中,注意: "your-username"是你当前用户的名字,比如root账户就是root,ubuntu账户就是ubuntu,可以通过命令whoami获取。

    adduser your-username qbittorrent-nox

3. 新建systemd文件,如下所示:

    touch /etc/systemd/system/qbittorrent-nox.service

使用你顺手的编辑器,比如vim/nano之类的,将以下内容填入刚才新建的文件中

    [Unit]Description=qBittorrent Command Line Client
    After=network.target [Service]Type=forking
    User=qbittorrent-nox
    Group=qbittorrent-nox
    UMask=007
    ExecStart=/usr/bin/qbittorrent-nox -d --webui-port=8080
    Restart=on-failure [Install]WantedBy=multi-user.target

4. 启用进程守护,直接执行以下命令就行了,最后一条命令执行完,出现active关键字就说明一切都如预期的那样跑起来了。

    systemctl daemon-reload
    systemctl start qbittorrent-nox
    systemctl enable qbittorrent-nox
    systemctl status qbittorrent-nox

至此,在浏览器中输入服务器的IP和qbittorrent-nox的端口就可以进入了,例如http://1.1.1.1:8080,这里的1.1.1.1是服务器的IP,8080是刚才进程守护文件中写入的端口。用户名是admin,用户密码:adminadmin。
强烈建议进去之后,立马修改用户名和用户密码!!!具体位置在tool>options>webui这里,还可以修改成中文。
Nginx反代qbittorrent-nox的Web-GUI

1. 修改监听地址
http+非标端口,总让人强迫症犯了,所以搞了个SSL和Nginx反代,让qbittorrent-nox的Web-GUI看起来舒服一些。
首先,在tool>options>webui中,将监听的IP地址从*改成127.0.0.1,然后执行重启命令systemctl restart qbittorrent-nox以生效。这样只有服务器本地才能访问,其他都不行。

2. 安装Nginx并配置反代,安装命令如下:

    apt install nginx

修改配置文件/etc/nginx/sites-available/,将server_name _;中的_改成域名,在location /中注释掉try_files $uri $uri/ =404;,并将以下内容写入:

    proxy_pass http://127.0.0.1:8080/;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    http2_push_preload on;

到此处,执行nginx -t检查配置文件是否支持,如果都是ok,那就可以重启nginx,命令为systemctl reload nginx。
实际上,我还添加了SSL(需要先注释掉server中的listen 80 default_server;和listen [::]:80 default_server;两行
)。整体示例如下,就不细说了,可以对照着自己配置文件修改。如果不熟悉的,强烈建议使用Let's Encrypt等一键SSL/TLS程序添加SSL功能。

    server {

    #listen 80 default_server;
    #listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name qbt.example.com; # 此处的示例域名为qbt.example.com

    location / {
    #try_files $uri $uri/ =404;
    proxy_pass http://127.0.0.1:8080/;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    http2_push_preload on;
    }

    listen 443 ssl;

    ssl_certificate /path/qbt.example.com_bundle.crt; # SSL/TLS的证书,注意路径
    ssl_certificate_key /path/qbt.example.com.key; #SSL/TLS的密钥,注意路径
    ssl_session_timeout 5m;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; #开启了HSTS

    access_log /var/log/nginx/access.qbt.example.com.log; #记录访问日志
    error_log /var/log/nginx/error.qbt.example.com.log; #记录错误日志

    }

    server { #此功能为强制所有http跳转到https

    listen 80 default_server;
    server_name qbt.example.com;
    return 301 https://$host$request_uri;

    }

热议
推荐楼 雨墨 昨天20:10

反代与否不是太重要

3楼 imes 昨天20:15

反代与否不是太重要

对,我只不过是强迫症

4楼 zxxx 昨天20:16

技术贴,顶起来

5楼 惜为伊人醉 昨天20:18

支持一下技术贴!

6楼 32MB.CN 昨天20:25

docker 不好用吗?我现在很少直接装了

7楼 千牛 昨天20:33

qbit我也不这么装,都是docker启动,配置文件配一次,以后都用这个配置文件,每次docker启动就行了

8楼 张禹希 昨天20:35

docker 不好用吗?我现在很少直接装了

docker没有ipv6

9楼 心上人 昨天20:37

技术贴,支持一下

10楼 emmccc 昨天20:40

技术贴,支持一下

12楼 mbsi 昨天20:58

很好,我选择一键脚本

13楼 spr1ng 昨天21:13

感谢分享

申明:本文内容由网友收集分享,仅供学习参考使用。如文中内容侵犯到您的利益,请在文章下方留言,本站会第一时间进行处理。

退出移动版