Debian 11安装qbittorrent-nox并设置Nginx反代

debian
因为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;

}

 

 

本站文章资源均来源自网络,除非特别声明,否则均不代表站方观点,并仅供查阅,不作为任何参考依据!
如有侵权请及时跟我们联系,本站将及时删除!
如遇版权问题,请查看 本站版权声明
THE END
分享
二维码
海报
Debian 11安装qbittorrent-nox并设置Nginx反代
因为PT站优先qbittorrent,所以弃用aria2,而在Debian 11上安装qbittorrent,并配置Nginx反代。注意:qbittorrent是自带GUI的,适用于桌面环境;而qbittorren……
<<上一篇
下一篇>>
文章目录
关闭
目 录