RTorrent/RuTorrent
ruTorrent 是 PHP 前端/Web 界面,用于 rTorrent(一个基于控制台的 BitTorrent 客户端)。它使用 rTorrent 内置的 XML-RPC 服务器与之通信。
它轻巧、高度可扩展,并且设计得类似于 uTorrent。
安装
从 AUR 安装 rutorrentAUR。 如果您想使用开发版本,请安装 rutorrent-gitAUR。
配置
请参阅上游 wiki 此处。 默认情况下,配置文件符号链接到 /etc/webapps/rutorrent/conf
。
Web 服务器配置
Apache 2.4
根据 LAMP 页面安装和配置带有 PHP 的 Apache。
- 编辑 /etc/php/php.ini 中的 open_basedir 值以包含
/etc/webapps/rutorrent/conf/:/usr/share/webapps/rutorrent/php/:/usr/share/webapps/rutorrent/
- 在 UNIX 套接字上启用 rTorrent XMLRPC 接口:rTorrent#XMLRPC 接口
- 通过将以下内容添加到
/etc/httpd/conf/httpd.conf
中,在您为 rTorrent 选择的套接字上启用 SCGI
ProxyPass /RPC2 scgi:///path/to/rpc.socket
- 最后,将 ruTorrent 文件夹添加到
/etc/httpd/conf/httpd.conf
作为目录别名
<IfModule alias_module> Alias /rutorrent /usr/share/webapps/rutorrent <Directory "/usr/share/webapps/rutorrent"> Require all granted </Directory> </IfModule>
作为虚拟主机
<VirtualHost *:80> ServerName torrent.yourwebsite.com DocumentRoot /usr/share/webapps/rutorrent <Directory "/usr/share/webapps/rutorrent"> Options -Indexes -MultiViews Require all granted AllowOverride all </Directory> </VirtualHost>
Nginx
- 从您的 Web 根目录创建到 rutorrent 的链接
ln -s /usr/share/webapps/rutorrent/ /usr/share/nginx/html/rutorrent
- 编辑 /etc/php/php.ini 中的 open_basedir 值以包含
/etc/webapps/rutorrent/conf/:/usr/share/webapps/rutorrent/php/:/usr/share/webapps/rutorrent/
- 启用 rTorrent XMLRPC 接口:rTorrent#XMLRPC 接口
- 在
/etc/webapps/rutorrent/conf/config.php
中编辑以下位置到您的 rutorrent 配置,其中 rtorrentuser 是运行 rutorrent 的用户
$scgi_port = 0; $scgi_host = "unix:///home/rtorrentuser/rpc.socket";
注意:多用户设置将需要在 /usr/share/webapps/rutorrent/conf/users
下为每个用户的套接字位置设置用户特定的配置文件。 创建一个以用户名命名的文件夹,然后创建一个 config.php,例如
/usr/share/webapps/rutorrent/conf/users/rtorrentuser/config.php /usr/share/webapps/rutorrent/conf/users/anotheruser/config.php
- 重启
nginx.service
。
- 您现在可以通过 http://127.0.0.1/rutorrent 访问 ruTorrent
Lighttpd
rtorrent 应该使用 XML-RPC 支持编译。
将以下行添加到您的 rtorrent 配置文件中,通常是 ~/.rtorrent.rc
。
scgi_port = 127.0.0.1:5050
除了使用 tcp 端口外,也可以使用套接字,使用 scgi_local 选项代替,但是 lighttpd 可能会抱怨权限,无论套接字文件的权限/位置如何。
您可以选择 5050 以外的端口,如果您愿意。
lighttpd
安装 Lighttpd 和 PHP: lighttpd php php-cgi fcgi。
按照 wiki 的说明启动 lighttpd 后,您应该能够通过 https://127.0.0.1:80 访问测试页面。
默认情况下,页面从 /srv/http
提供,这是我们将放置 rutorrent 的位置。
lighttpd.conf
编辑 lighttpd 的配置文件,/etc/lighttpd/lighttpd.conf
。
以下行告诉 lighttpd 加载 fastcgi 和 simple-cgi 模块。 Fast cgi 是 rutorrent 本身需要的,而 scgi 用于 rutorrent 与 rtorrent 通信。
server.modules += ( "mod_fastcgi" ) server.modules += ( "mod_scgi" )
我们需要告诉 lighttpd 如何处理 css、图像(jpg 等)、js 等文件。 否则,它将不知道如何处理它们,您可能会收到一个对话框来下载文件,或者 rutorrent 将无法正常工作。
这是一个很长的文件类型列表,可能有点过分,因为其中大多数是不需要的,但更容易全部覆盖。
/etc/lighttpd/lighttpd.conf
mimetype.assign = ( ".rpm" => "application/x-rpm", ".pdf" => "application/pdf", ".sig" => "application/pgp-signature", ".spl" => "application/futuresplash", ".class" => "application/octet-stream", ".ps" => "application/postscript", ".torrent" => "application/x-bittorrent", ".dvi" => "application/x-dvi", ".gz" => "application/x-gzip", ".pac" => "application/x-ns-proxy-autoconfig", ".swf" => "application/x-shockwave-flash", ".tar.gz" => "application/x-tgz", ".tgz" => "application/x-tgz", ".tar" => "application/x-tar", ".zip" => "application/zip", ".mp3" => "audio/mpeg", ".m3u" => "audio/x-mpegurl", ".wma" => "audio/x-ms-wma", ".wax" => "audio/x-ms-wax", ".ogg" => "application/ogg", ".wav" => "audio/x-wav", ".gif" => "image/gif", ".jar" => "application/x-java-archive", ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".png" => "image/png", ".xbm" => "image/x-xbitmap", ".xpm" => "image/x-xpixmap", ".xwd" => "image/x-xwindowdump", ".css" => "text/css", ".html" => "text/html", ".htm" => "text/html", ".js" => "text/javascript", ".asc" => "text/plain", ".c" => "text/plain", ".cpp" => "text/plain", ".log" => "text/plain", ".conf" => "text/plain", ".text" => "text/plain", ".txt" => "text/plain", ".dtd" => "text/xml", ".xml" => "text/xml", ".mpeg" => "video/mpeg", ".mpg" => "video/mpeg", ".mov" => "video/quicktime", ".qt" => "video/quicktime", ".avi" => "video/x-msvideo", ".asf" => "video/x-ms-asf", ".asx" => "video/x-ms-asf", ".wmv" => "video/x-ms-wmv", ".bz2" => "application/x-bzip", ".tbz" => "application/x-bzip-compressed-tar", ".tar.bz2" => "application/x-bzip-compressed-tar", # default mime type "" => "application/octet-stream", )
接下来,我们添加 scgi 的配置以连接到 rtorrent。 确保使用与配置 rtorrent 时相同的端口。
scgi.server = ( "/RPC2" => ( "127.0.0.1" => ( "host" => "127.0.0.1", "port" => 5050, "check-local" => "disable" ) ) )
最后是 fastcgi 设置,以便 lighttpd 知道如何处理 php。
fastcgi.server = ( ".php" => (( "bin-path" => "/usr/bin/php-cgi", "socket" => "/tmp/php.socket" )))
测试
此时,您应该可以使用 xmlrpc 命令来测试 rtorrent 和 lighttpd 的 scgi 是否正常工作,以请求 rtorrent 的函数列表。(请参阅 https://github.com/rakshasa/rtorrent/wiki/RPC-Setup-XMLRPC#test-and-usage )。
$ xmlrpc localhost system.listMethods
这应该输出可以通过 rtorrent 的 scgi 接口访问的方法的日志列表。 如果没有,则可能存在问题。 如果您收到错误 500(内部服务器错误),请确保 rTorrent 正在运行。
php.ini
我们需要对 /etc/php/php.ini
中的 open_basedir 行进行一些小的更改,以允许 rutorrent 访问它需要运行的二进制文件。
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/bin
二进制文件是 stat、id、php、curl、gzip。 如果这些文件安装在 /usr/bin
以外的其他位置,则您可能还需要将其附加到该行。
rutorrent
我们将 rutorrent 下载到 lighttpd http 目录。
# cd /srv/http # wget https://github.com/Novik/ruTorrent/archive/v3.9.tar.gz # tar xvfx rutorrent-3.9.tar.gz # mv ruTorrent-3.9/ rutorrent/ # chown -R http rutorrent/ # rm rutorrent-3.9.tar.gz
这些应该下载 rutorrent 并将其解压到 /srv/http
。 您可能需要将 rutorrent-3.6 更改为 rutorrent 网站上所需的版本。
rutorrent 的配置文件位于 /srv/http/rutorrent/conf/
中。
我们需要编辑 /srv/http/rutorrent/conf/config.php
,并将端口更改为我们在 rtorrent 和 lighttpd 中使用的端口。
$scgi_port = 5050; $scgi_host = "127.0.0.1";
将 rutorrent 的所有者更改为 http(lighttpd 默认运行的用户)。
# chown -R http rutorrent
测试
rutorrent 现在应该已设置好。
启动 rtorrent,如果您自更改配置后尚未重启 lighttpd,请重启 lighttpd。
您现在应该可以在 localhost 或 127.0.0.1 的 80 端口上访问 rutorrent 界面(假设您没有更改 lighttpd 的默认端口)。
插件
要为 rutorrent 安装插件,请下载您想要的插件的存档并解压到 rutorrent 的插件目录。
/srv/http/rutorrent/plugins
插件可以在 rutorrent 网站上找到:https://code.google.com/p/rutorrent/wiki/Plugins
SSL 和身份验证
用户身份验证
有关不同身份验证方法的详细信息,请参见此处: https://redmine.lighttpd.net/projects/1/wiki/Docs_ModAuth
在此示例中,我们将使用 htdigest 方法进行摘要式身份验证。
在您的 lighttpd 目录中,我们将创建一个名为 lighttpd-htdigest.user
或您选择的其他文件名的文件来保存密码。
对于 htdigest,行的格式为
username:Realm:hash
用户名是您所需的用户名,Realm 是您选择给访问级别指定的名称。 Hash 是一个看起来像这样的字符串的 md5sum
username:Realm:password
因此,您的实际密码未存储在文件中,它只是对 md5sum 做出贡献。
因此,使用用户名:“tom”,Realm:“rtorrent”和密码:“secret_pass”,我们可以通过运行以下命令获得哈希值
$ echo -n "tom:rtorrent:secret_pass" | md5sum | cut -b -32 6a4aaa1091eb2d1d025bbd692dee3f0c
-n 告诉 echo 不要打印换行符,cut 命令仅获取前 32 个字节,因此我们不会在末尾得到破折号。
现在通过运行以下命令将其保存到变量中
$ hash=$(echo -n "tom:rtorrent:secret_pass" | md5sum | cut -b -32) $ echo $hash 6a4aaa1091eb2d1d025bbd692dee3f0c
现在将其保存到我们的密码文件中
# echo "tom:rtorrent:$hash" > /etc/lighttpd/lighttpd-htdigest.user
您可以使用任何文件名,只需将相同的文件添加到 lighttpd.conf
。
如果 root 作为此文件的所有者不起作用,请尝试 http
# chown http /etc/lighttpd/lighttpd-htdigest.user # chmod 400 /etc/lighttpd/lighttpd-htdigest.user
现在我们将更改 /etc/lighttpd/lighttpd.conf
以告诉它在每次访问 rutorrent 时都使用此密码文件。
添加以下行
server.modules += ( "mod_auth" ) auth.debug = 0 auth.backend = "htdigest" auth.backend.htdigest.userfile = "/etc/lighttpd/lighttpd-htdigest.user"
auth.require = ( "/rutorrent/" => ( "method" => "digest", "realm" => "rtorrent", "require" => "valid-user" ))
重启 lighttpd,现在当您重新加载 rutorrent 时,它应该要求您输入用户名和密码。
重启 lighttpd.service
。
SSL
请参阅 Lighttpd#通过 SSL 启用 https。 以下资源可以帮助您将 ssl 添加到 lighttpd [1][2]。
如果您只是想使其工作,则以下命令应该有效。
创建 pem 文件
# mkdir /etc/lighttpd/certs # openssl req -new -x509 -newkey rsa:2048 -keyout /etc/lighttpd/certs/lighttpd.pem -out /etc/lighttpd/certs/lighttpd.pem -days 730 -nodes
然后将以下行添加到 /etc/lighttpd/lighttpd.conf
(如果您仍然想要启用纯 http,请删除“#”注释)
#$SERVER["socket"] == ":443" { ssl.engine = "enable" ssl.pemfile = "/etc/lighttpd/certs/lighttpd.pem" #}
并将此行从 80 更改为 443(如果您只想启用 ssl)
server.port = 443
然后 https 应该可以工作,并且取决于您更改的内容,http 可能不再工作。
注意:此证书未由证书颁发机构签名,因此您必须在 Firefox 中添加例外。
故障排除
对于 rutorrent 或 lighttpd 的问题,首先要检查的最佳位置可能是 lighttpd 日志文件,位于 /var/log/lighttpd/
中,特别是 error.log
。
$ tail /var/log/lighttpd/error.log