Installing rTorrent/rutorrent under nginx

Start with a fresh and updated install of Debian Jessie.

# apt-get update && apt-get dist-upgrade

Then install some packages:

# apt-get install nginx rtorrent php5-fpm php5-cli curl git-core

Then create a new user, so that you don’t act silly and run everything under root.
(I use a dedicated vm, so I already had a user created during the install phase.)

# editor /etc/nginx/sites-enabled/default

upstream php-handler {
server unix:/var/run/php5-fpm.sock;
server {
listen 80;
server_name download.internal.local;
fastcgi_buffers 64 4K;
root /var/www/html;
index index.html;
error_page 404 /index.html;
location /RPC2 {
include scgi_params;
scgi_pass unix:/tmp/rpc.socket;
location ~ ^/(conf|share|\.ht|db_structure\.xml|README) {
deny all;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass php-handler;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf|svg)$ {
expires 30d;
access_log off;

Save the file, dont bother restart nginx.

Now to autostart rTorrent on each boot:

# editor /lib/systemd/system/rtorrent.service


 ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent
 ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent


Change User to the username you allocated, save and close the file, and enable the service:
# systemctl enable rtorrent


Change context to the defined user;
# su -l <username>
Create the session-directory:
$ mkdir .session

Create config for rTorrent
$ editor .rtorrent.rc

download_rate = 1248
 upload_rate = 256
 directory = /mnt/
 session = /home/CHANGEME/.session
 port_range = 9500-9500
 port_random = yes
 dht = disable
 set_dht_port = 9501
 peer_exchange = yes
 scgi_local = /tmp/rpc.socket
 schedule = chmod,0,0,"execute=chmod,777,/tmp/rpc.socket"
 encoding_list = UTF-8
 system.method.set_key =
 execute = {sh,-c,/usr/bin/php /var/www/html/php/initplugins.php &}

Consider changing directory, port-ranges and rates to your needs.
Save and close the file.

Change to web-directory, and checkout ruTorrent.

# cd /var/www/html/

# git clone .
(if this complains that the dir is not empty, do “# rm index.nginx-debian.html” first.)

When done, reconfigure ruTorrent for socket-communication:
# editor conf/config.php

Comment out $scgi_port and $scgi_host.

$scgi_port = 0;
$scgi_host = "unix:///tmp/rpc.socket";

Also fill in the path to curl ( /usr/bin/curl ).
I also change topDirectory to the dir my downloads should go, makes for easier browsing. (remember the trailing /)

Fix some permission issues,
# chown -R www-data share/

Save and close the file, technically ruTorrent/rTorrent works now – but all plugins are enabled which will generate some errors, and they are technically not needed.

# sed 's/ user-defined/ no/g' conf/plugins.ini -i

#editor conf/plugins.ini
Enable the plugins you want by typing in the following:

enabled = yes

This enables the loadavg-plugin. (remove the ‘\’, for some reason wordpress

Reboot the case, and remember to open firewall. (by following this guide, that will be tcp/80, tcp/9500, and tcp/9501.


Running ot-recorder (OwnTracks) from systemd

# editor /lib/systemd/system/ot-recorder.service


ExecStart=/usr/local/sbin/ot-recorder -H localhost -p 8883 –norec –http-host <localip> –clientid <username> “owntracks/#”


# editor /etc/mosquitto/environment