Custom Base URL for Reverse Proxy

Get help, report and discuss bugs.
Post Reply
blindpet
Posts: 42
Joined: 02 May 2014, 10:27
Contact:

Custom Base URL for Reverse Proxy

Post by blindpet » 27 Dec 2014, 09:53

I can get nzbget to sit behind the location /nzbget in nginx no problem.

As soon as I try to use a different location like /usenet I get a 404. I noticed there is no url base I can edit like in other programs. The closest thing I could find was the WebUI directory which I copied from /usr/share/nzbget to /usr/share/usenet. When I restart the service it just says Loading when I try to go to ip.address:6789.

Any ideas?

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: Custom Base URL for Reverse Proxy

Post by hugbug » 27 Dec 2014, 15:05

Were you using this doc - http://nzbget.net/NZBGet_behind_other_web-server ?
When I tried nginx (a long time ago) I was able to use any paths. The same for apache. Only lighttpd was limited.

blindpet
Posts: 42
Joined: 02 May 2014, 10:27
Contact:

Re: Custom Base URL for Reverse Proxy

Post by blindpet » 28 Dec 2014, 22:01

Using exactly that doc, which version of nginx was it you tested on? I have someone I'm helping and they can't get it working either, only location ~ ^/nzbget($|./*) works.

I was on nginx 1.2.1 and just upgraded to 1.6.2 and there was no change.

NZBGet 14.1 log shows these errors

Code: Select all

Sun Dec 28 2014 23:26:19	Web-Server: 404 Not Found, Resource: /usenet/
warning	Sun Dec 28 2014 23:25:59	Web-Server: 400 Bad Request, Resource: /usenet/jsonrpc
Last edited by blindpet on 28 Dec 2014, 22:31, edited 1 time in total.

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: Custom Base URL for Reverse Proxy

Post by hugbug » 28 Dec 2014, 22:16

That was a long time ago, I can't remember the version anymore. I also not sure that I really tried different subdirectories :oops: I'm sure I did with apache.

Please try adding a rewrite-command as in this example from here :
Reverse proxy for a subdirectory

Here's an excerpt of a basic nginx configuration that proxies the URL "http://domain.com/couchdb" to "http://localhost:5984" so that requests appended to the subdirectory, such as "http://domain.com/couchdb/db1/doc1" are proxied to "http://localhost:5984/db1/doc1".

location /couchdb {
rewrite /couchdb/(.*) /$1 break;
proxy_pass http://localhost:5984;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
I don't have nginx installed at the moment; I think you can test it quicker than me.

blindpet
Posts: 42
Joined: 02 May 2014, 10:27
Contact:

Re: Custom Base URL for Reverse Proxy

Post by blindpet » 28 Dec 2014, 23:05

No worries, I had messed with rewrites and none of them worked, neither did this one unfortunately ;(

I have also tried adding the webui location root /usr/share/nzbget/webui to the configuration and I still get 404 error (not from nginx though)

The only way I have gotten it to work is a custom location that proxies /customlocation to the /nzbget location.

Sonarr, CouchPotato, SickBeard and SickRage all have this custom base url that you can modify so that it works with any URL you choose. Is it possible to implement such a feature in NZBGet?

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: Custom Base URL for Reverse Proxy

Post by hugbug » 05 Jan 2015, 14:05

As suggested above the rewrite-command does the trick.

This config works:

Code: Select all

		location ~ ^/usenet($|./*) {
			rewrite /usenet/(.*) /$1 break;
			proxy_pass http://127.0.0.1:6789;
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		}
		location ~ ^/usenet$ {
			return 302 $scheme://$host$request_uri/;
		}
Replace "usenet" (all three occurrences) with anything you like.

The redirect-command (second location-definition) is useful to make sure the URL typed without trailing slash does work too.

salami
Posts: 68
Joined: 14 Apr 2014, 11:09
Location: Switzerland

Re: Custom Base URL for Reverse Proxy

Post by salami » 16 May 2015, 10:23

Looks like you have to put the redirect block before the main location block to get URLs other than /nzbget to work without a trailing slash. Otherwise they seem to match to the main block which breaks it:

Code: Select all

WARNING	Web-Server: 404 Not Found, Resource: /usenet
At least that's what's happening to me with nginx 1.8.0. This works perfectly for me:

Code: Select all

	location ~ ^/n$ {
	   return 302 $scheme://$host$request_uri/;
	}
	location ~ ^/n($|./*) {
	   rewrite /n/(.*) /$1 break;
	   proxy_pass http://127.0.0.1:6789;
	   proxy_set_header Host $host;
	   proxy_set_header X-Real-IP $remote_addr;
	   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}

PhAzE
Posts: 1
Joined: 08 Sep 2015, 21:03

Re: Custom Base URL for Reverse Proxy

Post by PhAzE » 08 Sep 2015, 21:05

I suppose this has not been resolved in current builds of this app?

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: Custom Base URL for Reverse Proxy

Post by hugbug » 08 Sep 2015, 21:16

It always worked, nothing to fix.

Post Reply

Who is online

Users browsing this forum: No registered users and 50 guests