0

I want to use NGINX to as a proxy to get to Deluge which is inside my home network (NGINX is publically available).

This configuration works:

location 8112;

location / {
    proxy_pass http://deluge_address:8112;
}

However I'd like to use an address in form of http://nginx_address/deluge to be proxied to internal http://deluge_address:8112.

I tried the following:

location /deluge/ {
    proxy_pass http://deluge_address:8112/;
}

(I tried different combinations of trailing / - none work).

But I get 404 Not found instead.

I have some knowledge about networks, but not too much. Does anybody have any idea what I'm doing wrongly?

Werolik
  • 923
  • 1
  • 9
  • 23
  • Is Deluge a HTML based website ? If yes then it may or may not work. Suppose deluge front page has a link "/abc", deluge expects it to be available at `http://nginx_address/abc", but you expect the page to request "http://nginx_address/deluge/abc". But since the browser is making this request it won't work – Tarun Lalwani Aug 29 '17 at 08:56
  • Deluge is not reaching to outside - it's just a web UI for the service hosted at `deluge_address` (you can see it here https://www.howtogeek.com/142044/how-to-turn-a-raspberry-pi-into-an-always-on-bittorrent-box/) – Werolik Aug 29 '17 at 09:18

2 Answers2

2

I did find a solution for this, but found a bug also in Nginx in the same time

https://trac.nginx.org/nginx/ticket/1370#ticket

Edit-1

Seems like bug i logged was an invalid one, which even helped me understand few more things. So I edited the config a bit.

You need to use below config

location ~* /deluge/(.*) {
    sub_filter_once off;
    sub_filter_types text/css;
    sub_filter '"base": "/"' '"base": "/deluge/"';
    sub_filter '<head>' '<head>\n<base href="/deluge/">';
    sub_filter 'src="/' 'src="./';
    sub_filter 'href="/' 'href="./';
    sub_filter 'url("/' 'url("./';
    sub_filter 'url(\'/' 'url(\'./';

    set $deluge_host 192.168.33.100;
    set $deluge_port 32770;
    proxy_pass http://$deluge_host:$deluge_port/$1;
    proxy_cookie_domain $deluge_host $host;
    proxy_cookie_path / /deluge/;
    proxy_redirect  http://$deluge_host:$deluge_port/ /deluge/;
}

The key was to insert a base url into the pages using below

sub_filter '<head>' '<head>\n<base href="/deluge/">';

And then make replacement in src and href attributes in html. And also url(' in css entries.

Luckily deluge has a JavaScript config which has the base url. So we can override the same by adding

sub_filter '"base": "/"' '"base": "/deluge/"';
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • I tried it as is (by changing deluge host and port variables to mine) - unfortunately, doesn't work. I still get 404. I'll try to move in this direction. Could you maybe tell me, how I can find out, what calls NGINX tries to make and what the response is? – Werolik Aug 31 '17 at 07:03
  • I tested this using docker and it worked fine for me. This is what i ran `docker run -P -d -it linuxserver/deluge`. You can try my solution using that – Tarun Lalwani Aug 31 '17 at 07:20
  • It worked as is in the end. Not sure, what was wrong. I tried commenting everything out and uncommenting line by line - in the end, it just worked. I just added two lines to enable logging (access/error log). Thanks! – Werolik Sep 03 '17 at 15:45
  • P.S. I installed NGINX without docker, doesn't matter anyway. – Werolik Sep 03 '17 at 15:47
  • This worked perfect using ghcr.io/linuxserver/deluge – user3246446 Jul 23 '21 at 11:45
0

I faced the same problem, luckily I found a better and official solution:

Reverse Proxy with Deluge WebUI

    proxy_set_header X-Deluge-Base "/deluge/";
    add_header X-Frame-Options SAMEORIGIN;

My final settings:

  location /deluge {
    proxy_pass http://127.0.0.1:8112/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header 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;
    proxy_connect_timeout 75;
    proxy_send_timeout 3650;
    proxy_read_timeout 3650;
    proxy_buffers 64 512k;
    client_body_buffer_size 512k;
    client_max_body_size 0;
    # https://dev.deluge-torrent.org/wiki/UserGuide/WebUI/ReverseProxy
    proxy_set_header X-Deluge-Base "/deluge/";
    add_header X-Frame-Options SAMEORIGIN;
  }

Luiz Vaz
  • 1,669
  • 1
  • 19
  • 32