rtorrent + rutorrent + nginx + php-fpm. Underwater rocks
The previous article about the rtorrent + rutorrent + nginx + php-fpm bundle was written immediately after the successful installation and initial configuration of this bundle. During the operation, some pitfalls were revealed, which I want to talk about.
It turned out that the nginx bundle with rutorrent + rtorrent worked fine, it’s enough to write the following lines in the conf / config.php file in the rutorrent installation directory tree: In this case, the network socket in the rtorrent ~ / .rtorrent.rc settings file is enough: nginx has more you don’t need to write a backend for / RPC2, but from the rtorrent startup scripts you need to remove the work with a local UNIX socket to control rtorrent.
Naturally, in order for rutorrent to work successfully, it is necessary for the user on behalf of whom the nginx and php-fpm daemons work, to give rights to all files and directories of the rutorrent installation. In my case, the command does this:
When using php-fpm locally, it is better to put it on a UNIX socket. To do this, in the /etc/php/php-fpm.conf file, you need to comment out the line with the network socket:
And enter the line with the UNIX socket below:
After that, you need to reconfigure nginx. In the file /etc/nginx/conf/nginx.conf, we convert the backend block to this form:
Using UNIX sockets reduces the load on the system, as checksums are not calculated, and the data stream is sent directly to the receiving buffer. Critical only for embedded solutions.
When using nginx locally, it is best to land at 127.0.0.1. To do this in the file /etc/nginx/conf/sites-enabled/rutorrent.eternity line listen should be reduced to this form:
If you do not, the web interface will be able to take advantage of someone who knows the IP-address. To be able to remotely control rtorrent, you should take care of authentication (at least through nginx basic authentication).
In order for the rutorrent module called geoip to work, you must install the appropriate extension for PHP. In my case ( Arch Linux ), this action looks like this:
Then, in the /etc/php/conf.d/geoip.ini file, you need to remove a comment from a single line so that it looks like this:
You also need to activate the JSON plugin. This is done in the creation of the catalog /etc/php/conf.d file json.ini with this content:
No plugin json nothing will work.
In order for rutorrent to find additional programs ( curl, stat, mediainfo ), firstly, they need to be installed:
Secondly, you need to enable their execution. To do this, in the /etc/php/php.ini file, you need to comment out the line open_basedir:
And, thirdly, you need to register additional programs in the rutorrent configuration. CURL and stat are written in the conf / config.php file of the rutorrent installation directory tree in this way:
The path to the mediainfo program is specified in the plugins / mediainfo / conf.php file in the rutorrent installation directory tree in this way:
These paths can be omitted if the user, on behalf of whom the daemons of the web part of the bundle work, is set to the PATH environment variable.
For myself, I made a script with the following contents:
This script is given the right to execute: And the script itself is moved to / usr / bin : Then somewhere on the socket of my DE ( I did everything in xfce ) a button is hung to launch this script. If rtorrent is not running, then the script will launch it, and if it is running, it will turn it off, while displaying a pop-up notification on the screen via libnotify. Of course, you need to install libnotify for this:
After performing all of the above steps, you must restart php-fpm and nginx:
As a result, the chances that rutorrent will work fully increase significantly.
UPDATE 1: added some explanation.
UPDATE 2: updated section with RPC. Thanks svin0 .
Rpc
It turned out that the nginx bundle with rutorrent + rtorrent worked fine, it’s enough to write the following lines in the conf / config.php file in the rutorrent installation directory tree: In this case, the network socket in the rtorrent ~ / .rtorrent.rc settings file is enough: nginx has more you don’t need to write a backend for / RPC2, but from the rtorrent startup scripts you need to remove the work with a local UNIX socket to control rtorrent.
$scgi_port = 33333;
$scgi_host = "127.0.0.1";
scgi_port = 127.0.0.1:33333
Access rights
Naturally, in order for rutorrent to work successfully, it is necessary for the user on behalf of whom the nginx and php-fpm daemons work, to give rights to all files and directories of the rutorrent installation. In my case, the command does this:
sudo chown -R http:http /srv/http/nginx/rutorrent.eternity/htdocs
Php-fpm socket
When using php-fpm locally, it is better to put it on a UNIX socket. To do this, in the /etc/php/php-fpm.conf file, you need to comment out the line with the network socket:
;listen = 127.0.0.1:9000
And enter the line with the UNIX socket below:
listen = /var/run/php-fpm/php-fpm.sock
After that, you need to reconfigure nginx. In the file /etc/nginx/conf/nginx.conf, we convert the backend block to this form:
upstream backend {
server unix:/var/run/php-fpm/php-fpm.sock;
}
Using UNIX sockets reduces the load on the system, as checksums are not calculated, and the data stream is sent directly to the receiving buffer. Critical only for embedded solutions.
Security
When using nginx locally, it is best to land at 127.0.0.1. To do this in the file /etc/nginx/conf/sites-enabled/rutorrent.eternity line listen should be reduced to this form:
listen 127.0.0.1:80;
If you do not, the web interface will be able to take advantage of someone who knows the IP-address. To be able to remotely control rtorrent, you should take care of authentication (at least through nginx basic authentication).
geoip
In order for the rutorrent module called geoip to work, you must install the appropriate extension for PHP. In my case ( Arch Linux ), this action looks like this:
sudo pacman -S php-geoip
Then, in the /etc/php/conf.d/geoip.ini file, you need to remove a comment from a single line so that it looks like this:
extension=geoip.so
You also need to activate the JSON plugin. This is done in the creation of the catalog /etc/php/conf.d file json.ini with this content:
extension=json.so
No plugin json nothing will work.
Supporting Programs
In order for rutorrent to find additional programs ( curl, stat, mediainfo ), firstly, they need to be installed:
sudo pacman -S curl mediainfo
Secondly, you need to enable their execution. To do this, in the /etc/php/php.ini file, you need to comment out the line open_basedir:
;open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/
And, thirdly, you need to register additional programs in the rutorrent configuration. CURL and stat are written in the conf / config.php file of the rutorrent installation directory tree in this way:
$pathToExternals = array(
"php" => '',
"curl" => '/usr/bin/curl',
"gzip" => '',
"id" => '',
"stat" => '/usr/bin/stat',
);
The path to the mediainfo program is specified in the plugins / mediainfo / conf.php file in the rutorrent installation directory tree in this way:
$pathToExternals['mediainfo'] = '/usr/bin/mediainfo';
These paths can be omitted if the user, on behalf of whom the daemons of the web part of the bundle work, is set to the PATH environment variable.
Snacks
For myself, I made a script with the following contents:
#!/usr/bin/env bash
delay="1000"
pid1=`pidof rtorrent`
if [[ $pid1 != "" ]]
then
notify-send -t $delay "Останавливаю rtorrentd…"
sudo rc.d stop rtorrentd
notify-send -t $delay "rtorrentd остановлен"
else
notify-send -t $delay "Запускаю rtorrentd…"
sudo rc.d start rtorrentd
notify-send -t $delay "rtorrentd запущен"
fi
This script is given the right to execute: And the script itself is moved to / usr / bin : Then somewhere on the socket of my DE ( I did everything in xfce ) a button is hung to launch this script. If rtorrent is not running, then the script will launch it, and if it is running, it will turn it off, while displaying a pop-up notification on the screen via libnotify. Of course, you need to install libnotify for this:
sudo chown root:root x-rtorrentd-wrapper.sh
sudo chmod 755 x-rtorrentd-wrapper.sh
sudo mv x-rtorrentd-wrapper.sh /usr/bin
sudo pacman -S libnotify
Restarting Demons
After performing all of the above steps, you must restart php-fpm and nginx:
sudo rc.d restart php-fpm nginx
As a result, the chances that rutorrent will work fully increase significantly.
UPDATE 1: added some explanation.
UPDATE 2: updated section with RPC. Thanks svin0 .