Bind address to loopback not working, results in Bad Request (Invalid host)

Hello,

Just wanted to start off by saying this is a great piece of software.

I’m looking to set the bind address to the loopback address (127.0.0.1 or localhost). Unfortunately I get the following when I use 127.0.0.1 or localhost as the bind address when I try to query the site in browser:

“Bad Request (Invalid host)”

Setting the bind address back to ‘*’ works but I want Sonarr to be only listening on the loopback address and I want it to be only accessible from the machine that is hosting Sonarr only and no where else. I’m running this on Ubuntu 15 with the latest released version of Sonarr. The version of Mono installed is the one included with the Sonarr repo. I have not tried installing a newer version of Mono (3.10 I think)

The logs show:
15-10-25 16:06:49.7|Info|OwinHostController|Listening on the following URLs:
15-10-25 16:06:49.7|Info|OwinHostController| http://127.0.0.1:8989/
15-10-25 16:06:49.7|Info|OwinHostController| http://localhost:8989/
15-10-25 16:06:49.8|Debug|OwinAppFactory|Attaching NzbDroneVersionMiddleWare to host
15-10-25 16:06:49.8|Debug|OwinAppFactory|Attaching SignalRMiddleWare to host
15-10-25 16:06:49.8|Debug|OwinAppFactory|Attaching NancyMiddleWare to host

So I know it is listening as expected. And using the browser does show the query is being received by the webserver and responding with the Bad Request message instead of the Sonarr content.

Netstat also shows:
Proto Recv-Q Send-Q Local Address Foreign Address State Timer
tcp 0 0 127.0.0.1:8989 0.0.0.0:* LISTEN off (0.00/0/0)

Let me know if I can provide more info to help resolve this bug. Setting the bind address back to * and accessing it through http://127.0.0.1:8989 works perfectly.

Thanks!

EDIT:
After some experimenting, I found using ssh port forwarding to remote machine that it seems to work. So I narrowed down to the fact Sonarr might not support Apache virtual hosts for reverse proxies. Seems to work with Couchpotato nzbget and other web hosted software. What I mean by virtual hosts is instead of url like example.com/sonarr, we do sonarr.example.com and reverse proxy to localhost:8989 (no need to set URL base in Sonarr). Reverse proxies allow access to ports open on loopback only. Again confirmed everything works when bind address is . The Sonarr web server doesn’t seem to like it if the URL is anything but the ip of the bind address if its not "" even if its proxied appropriately

After some researching, I found out there is a way for the reverse proxy to report the hostname of the destination name specified in the conf instead of changing it by setting the “ProxyPreserveHost Off” in your apache conf for the site. Posting the workaround here in case people face this issue in the future:

                <Proxy *>
                        Order deny,allow
                        Allow from all
                </Proxy>

                ProxyRequests Off
                ProxyPreserveHost Off  #this is key for it to work with Sonarr
                ProxyPass / http://127.0.0.1:8989/
                ProxyPassReverse / http://127.0.0.1:8989/

I believe this is still a bug though as the hostname should not be limited to the bind address. I leave the ‘ProxyPreserveHost On’ settings for all my other reverse proxied sites.

The issue is it binds the hostname (or IP) and doesn’t limit connections to the specified IP, which unfortunately at the moment its not something we can solve.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.