PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, June 24, 2022

[FIXED] How to proxy calls to specific URL to deluge using NGINX?

 June 24, 2022     deluge, nginx, proxy, reverse-proxy     No comments   

Issue

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?


Solution

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/"';


Answered By - Tarun Lalwani
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing