3

I have my working on default port and I want to be able to use the web interface with an URL like http://my.domain/torrents.

I tried adding a location and a proxy conf to Nginx but it fail to work fully. I guess it's because of web interface redirections.

server {
    root /data/www;
    autoindex on;

    server_name localhost;

    location / {
            try_files $uri $uri/ /index.html;
    }

    location /torrents/ {
            proxy_pass_header  X-Transmission-Session-Id;
            proxy_pass         http://127.0.0.1:9091;
    }
}

This conf fail because it can't reach /transmission/rpc (404 /usr/share/transmission/web/rpc) I have tried many things and I always have something missing. transmission/rpc or transmission/upload or transmission/web or transmission/javascript/whatever...

erch
  • 4,890
  • 17
  • 49
  • 81
Cyrbil
  • 369
  • 1
  • 4
  • 10

5 Answers5

6

I was able to get this working just now with the following location in my config:

      location /transmission {
              proxy_pass http://127.0.0.1:9091;
              proxy_pass_header X-Transmission-Session-Id;
              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     }

When I went to /transmission/, I got a 409 error saying that I had an invalid X-Transmission-Session-Id header, but when I went to /transmission/web everything seemed to be okay.

Roger Filmyer
  • 176
  • 1
  • 3
3

There is a working sample in Linuxserver.io repository.

https://github.com/linuxserver/reverse-proxy-confs/blob/master/transmission.subfolder.conf.sample

If you are not using docker, the configuration may look like this.

location ^~ /transmission {
    include proxy.conf;
    proxy_pass http://127.0.0.1:9091;
    proxy_pass_header  X-Transmission-Session-Id;
}

location ^~ /transmission/rpc {
    include proxy.conf;
    proxy_pass http://127.0.0.1:9091;
}

proxy.conf is in https://github.com/linuxserver/docker-swag/blob/master/root/defaults/nginx/proxy.conf.sample

yananet
  • 31
  • 4
1

Your config says that only urls which start with /torrents/ should be proxy_passed to http://127.0.0.1:9091. For any other url like /transmission nginx will use the first location / and hence not proxy_pass it to the backend.

If you want every request to be proxy passed to the backend, you would need this location instead of the two you have:

location / {
        proxy_pass_header  X-Transmission-Session-Id;
        proxy_pass         http://127.0.0.1:9091;
}
replay
  • 8,483
  • 1
  • 26
  • 31
  • Thanks for your answer, I use nginx as my web server so I don't want to forward all requests to the transmission web interface. Only those coming from /torrents/. But you point out that my basic web configuration may be one part of the problem. I will continu to investigate. – Cyrbil Feb 18 '13 at 14:11
  • You say you have this webinterface on /torrents, and it's linking to urls like /transmission, right? maybe the problem is just that this webinterface isn't aware of the /torrents prefix, so it generates the links wrong. so maybe the correct link would be /torrent/transmission? Then the problem is probably in the configuration of this webinterface, somewhere you would need to configure that the prefix for every url should be /torrent – replay Feb 18 '13 at 14:17
0

After googling and finding this post, the below is my nginx https enabled website's working proxy setup

server {
  listen         80 default_server;
  server_name    domain.com;
  rewrite        ^ https://$server_name$request_uri? permanent;
}

server {
  listen 443 default_server;

  server_name domain.com;
  root /var/www;

  ssl on;
  ssl_certificate /etc/nginx/ssl/transmission.cert;
  ssl_certificate_key /etc/nginx/ssl/transmission.key;

  ssl_session_timeout 5m;

  ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
  ssl_prefer_server_ciphers on;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/access.log;
  error_log   /var/log/nginx/error.log;

  #location /index {
  #  autoindex on;
  #}
  
   #TRANSMISSION TORRENT WEB CLIENT SETUP START FOR MY PI
        location /transmission/ {
        proxy_read_timeout 300;
        proxy_pass_header  X-Transmission-Session-Id;
        proxy_set_header   X-Forwarded-Host $host;
        proxy_set_header   X-Forwarded-Server $host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

        # if you changed the port number for transmission daemon, then adjust the
        # folllowing line
        proxy_pass         http://127.0.0.1:9091/transmission/web/;
        }

        # Also Transmission specific
    location /rpc {
        proxy_pass         http://127.0.0.1:9091/transmission/rpc;
    }
#TRANSMISSION TORRENT WEB CLIENT SETUP END

       
    location /upload {
        proxy_pass         http://127.0.0.1:9091/transmission/upload;
    }
}

here's the original gist

https://gist.github.com/michaelkeevildown/072b2f94af6bfa1416ee44c7004aff43

terdon
  • 234,489
  • 66
  • 447
  • 667
Kambaa
  • 101
  • 1
0

Do note that this seems to still throw a single 409 on the first RPC call, but this is just in the logs and otherwise seems to work just fine

To get around the /transmission not working directly and need to go to /transmission/web, I've added the rewrite rule. The remaining parts were already provided by @replay.

I have an SSL redirect and a few other services running on this nginx so can't just proxy pass everything through /

Assumption - all non '/' terminated paths are redirected to /, e.g. mydomain.com/transmission will be redirected to mydomain.com/transmission/

# Redirect /transmission to /transmission/web/ to get around the CSRF token issues
                location = /transmission/ {
                        return 301 /transmission/web/;
                }
# Actually proxy with the session id header 
# We need a separate proxy for /transmission, which is the webpage and assets and a separate for the rpc calls which go to the server root
                location ^~ /transmission {
                        include proxy.conf;
                        proxy_pass http://127.0.0.1:9091/transmission;
                        proxy_pass_header X-Transmission-Session-Id;
                }
                location ^~ /transmission/rpc {
                        include proxy.conf;
                        proxy_pass http://127.0.0.1:9091;
                }


I believe the proxy conf details are just defaults

# Version 2023/02/09 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/proxy.conf.sample

# Timeout if the real server is dead
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;

# Proxy Connection Settings
proxy_buffers 32 4k;
proxy_connect_timeout 240;
proxy_headers_hash_bucket_size 128;
proxy_headers_hash_max_size 1024;
proxy_http_version 1.1;
proxy_read_timeout 240;
proxy_redirect http:// $scheme://;
proxy_send_timeout 240;

# Proxy Cache and Cookie Settings
proxy_cache_bypass $cookie_session;
#proxy_cookie_path / "/; Secure"; # enable at your own risk, may break certain apps
proxy_no_cache $cookie_session;

# Proxy Header Settings
#proxy_set_header Connection $connection_upgrade;
proxy_set_header Early-Data $ssl_early_data;
proxy_set_header Host $host;
proxy_set_header Proxy "";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Method $request_method;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-Uri $request_uri;
proxy_set_header X-Original-Method $request_method;
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
proxy_set_header X-Real-IP $remote_addr;
Mae Nova
  • 1
  • 1