causefx / Organizr

HTPC/Homelab Services Organizer - Written in PHP
GNU General Public License v3.0
5.18k stars 292 forks source link

Unable to connect to Sonarr/Radarr from Homepage Item configuration #2004

Closed jarodwsams closed 3 months ago

jarodwsams commented 3 months ago
Organizr Version: V 2.1.2490
Branch: Master
WebServer: Nginx
Operating System: Docker

Problem Description:

I have Sonarr and Radarr configured in tabs, and the tabs work. Everything is accessed via NGINX reverse proxy on subdomains. When I try to configure the homepage item for either one, I get a Response was not JSON message when I test the connection. I have confirmed that the URLs and API Key entries are correct.

I can provide a scrubbed copy of my NGINX proxy-conf file, if that would be helpful, as I suspect that has something to do with this. I used the sample proxy-conf files that come in the Swag docker image from LSIO, and the only things I modified were the server name subdomains and the container names.

Again, the reverse proxy configuration works well in every aspect except this.


Reproduction Steps:
  1. Navigate to Settings > Tab Editor > Homepage Items
  2. Click on Sonarr
  3. Input my FQDN, which works otherwise, in the "Multiple URLs" input box (there are two each for Sonarr and Radarr)
  4. Input my Sonarr or Radarr API Keys in the "Multiple API Key/Tokens" input box
  5. Click Save
  6. Go to "Test Connection" and click the button to test the connection
  7. Get the aforementioned error in a toast message

Errors on screen? If so paste here:

API Error
https://sonarr1.mydomain.com: Response was not JSONhttps://sonarr2.mydomain.com: Response was not JSON
jarodwsams commented 3 months ago

TL;DR: I missed a piece of instruction, and now I've resolved the issue myself.

I ended up figuring this out. I had missed the help text on the "Multiple URLs" input box that instructs to use local IP addresses and ports. I did that (had to "toggle on" port publishing in my containers), and it worked. Then, for shits and giggles, I tried using the container hostnames with the internal ports, and that worked, as well.

Highlight: I've found that you can use docker container hostnames with internal (unpublished) ports. This assumes Organizr and Sonarr/Radarr/whatever else, are all accessible to each other on their happy little docker bridge.

jarodwsams commented 3 months ago

Oh, I should add that I had to also make some modifications to the NGINX proxy-conf files for the affected services.

Changes:

  1. Add this to the / location block:
        # Additional headers
        proxy_set_header Accept-Encoding "";
        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;
  2. Add this to the api location block:

        # JSON handling
        proxy_set_header Accept application/json;
    
        # Additional headers
        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;

These changes all came from the all-knowing ChatGPT, because I know just enough to be very, very dangerous to myself and those close to me. My understanding is that some of these are mostly for security, some are for allowing proper identification of the client, and some (the Accept application/json in particular), is to direct NGINX to explicitly allow JSON transaction.

If my understanding of these is incorrect, I apologize. I make no claim to being an expert in these things. YMMV.