Reverse proxy not working for Sonarr

1. Caddy version (caddy version):

v2.2.0 h1:sMUFqTbVIRlmA8NkFnNt9l7s0e+0gw+7GPIrhty905A=

2. How I run Caddy:

Use the caddy exe in a local directory. Config file in same directory.

a. System environment:

Windows 10

b. Command:

caddy start

c. Service/unit/compose file:

NA

d. My complete Caddyfile or JSON config:

cruizer.asus.com {

	log {
		output file access.log {
        		roll_size 5MiB         
        		roll_keep_for 168h     
        		roll_keep 2            
        	}
	}

	reverse_proxy /sonarr {
		to localhost:8989
	}
}

3. The problem I’m having:

I’m trying to use caddy as a reverse proxy for my Sonarr, Radarr services on the same machine. Will concentrate on Sonarr since I think I’m a little closer to getting it to work with caddy.

When I go to cruizer.asus.com/sonarr I get a 400 (HTTP Error 400. The request hostname is invalid.)

4. Error messages and/or full log output:

2020/10/13 01:05:34.827 error http.log.access.log0 handled request {“request”: {“remote_addr”: “192.168.1.1:51364”, “proto”: “HTTP/2.0”, “method”: “GET”, “host”: “cruizer.asus.com”, “uri”: “/sonarr”, “headers”: {“Accept-Encoding”: [“gzip, deflate, br”], “Dnt”: [“1”], “Upgrade-Insecure-Requests”: [“1”], “Te”: [“trailers”], “User-Agent”: [“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0”], “Accept”: [“text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8”], “Accept-Language”: [“en-US,en;q=0.5”]}, “tls”: {“resumed”: false, “version”: 772, “cipher_suite”: 4865, “proto”: “h2”, “proto_mutual”: true, “server_name”: “cruizer.asus.com”}}, “common_log”: “192.168.1.1 - - [13/Oct/2020:14:05:34 +1300] “GET /sonarr HTTP/2.0” 400 334”, “duration”: 0.0009976, “size”: 334, “status”: 400, “resp_headers”: {“Server”: [“Caddy”, “Microsoft-HTTPAPI/2.0”], “Content-Length”: [“334”], “Content-Type”: [“text/html; charset=us-ascii”], “Date”: [“Tue, 13 Oct 2020 01:05:34 GMT”]}}

5. What I already tried:

Rechecked port forwards on the router (443 to the box for TCP and UDP to be sure)
Tried various caddyfile configurations e.g. tried a trailing / on /sonarr/
Connecting to domain root gives me a blank page, I’m guessing the error is coming from Sonarr but not sure how to verify that.
I’ve done extensive research online to try and find an answer but most configurations I’m coming across are the same as mine.
Sonarr configured for /sonarr URL base

Tried this config:

cruizer.asus.com 

respond "test"

It works :+1:

I’ve spent about 3 hours on this so far with no luck :blush:

Thanks for your help!

6. Links to relevant resources:

Path matching is exact-match in Caddy v2 (/sonarr will only match exactly /sonarr but not /sonarr/foo), so you need to append a * to the end to match any subpath.

The HTTP 400 status is likely because sonarr is expecting the host to be something else. There must be some way to configure that.

That said, I typically recommend serving apps like Sonarr on subdomains rather than subpaths, for these reasons:

2 Likes

Thanks fransiclavoie. On your first bit, it certainly appears that Sonarr is expecting the host to be something it’s not. Weird that in hours of Googling I haven’t found another person with the issue.

What I change my caddyfile to be

localhost

reverse_proxy localhost:8989

it works perfectly

And

localhost

reverse_proxy /sonarr localhost:8989

Gives me everything you described in the subfolder problem article you linked to :laughing:

I think you can try this (as described in the subfolder article):

handle_path /sonarr* {
	reverse_proxy localhost:8989
}

This should work as long as sonarr properly uses relative paths for HTML links. If it doesn’t, you may need to configure it to change the base path, if possible.

Like I said though, using a subdomain would avoid any issues altogether, with something like this:

sonarr.example.com
reverse_proxy localhost:8989

I’m still not getting past the 400 with that config unfortunately.

Well at this point, it’s not an issue with Caddy, and it’s an issue with Sonarr config. Sonarr is returning that error, not Caddy.

1 Like

Yes it seems that way. Thanks for your help Francis.

For anyone else that comes across this, I managed to sort it out by running Sonarr as admin once to register all hostnames on the 8989 port. Also needed to declare the path as

reverse_proxy /sonarr* localhost:8989

as Sonarr returns everything with the trailing forward slash.

This topic was automatically closed after 30 days. New replies are no longer allowed.