evilhero / mylar

An automated Comic Book downloader (cbr/cbz) for use with SABnzbd, NZBGet and torrents
GNU General Public License v3.0
977 stars 173 forks source link

Web UI settings will not save with nginx reverse proxy #2406

Closed Crowley007 closed 4 years ago

Crowley007 commented 4 years ago

I'm trying to get reverse proxy to work, and it kind of does. But Web ui settings will not save, there is a red box "there was a error".

Nothing about the error is written to the log even with debug options on. But this seems to get logged every time I try save the settings with reverse proxy

2020-01-23 11:55:03 | INFO | Branch detected & set to : development

Windows 10 Branch: latest dev

My nginx config is currently just:

location /mylar { proxy_pass http://127.0.0.1:8090/mylar/; }

I have my server on port 9000

I have tried numerous different options in nginx (just trying to google what others use, my understanding is pretty limited) and nothing seems to make any difference.

http://192.168.1.100:8090/mylar/ -> settings save fine

http://192.168.1.100:9000/mylar/ -> there was a error

professionaltart commented 4 years ago

I'm not sure how much of this is needed for mylar so much as I just tried to push the same stuff onto every microservice, but my nginx conf file has:

location /mylar {
    proxy_pass          http://localhost:8090;
    include             proxy-control.conf;
    include             auth-basic.conf;
#   proxy_redirect      http:// https://;
}

It's accessible from both localhost:8090 and localhost/mylar

Are you sure you don't have a port conflict? Are the issues only happening if nginx is running that conf file, or the port needs to be non-default, too?

barbequesauce commented 4 years ago

Two things are needed - you need to set http_root in the Interface section of your config.ini (remember to shut down before editing it) and the right headers need to be returned by Nginx.

Here’s my nginx block:

location /mylar {
    proxy_pass http://mylarhost.local:9095;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_f
    proxy_redirect http:// https://;
    access_log /var/log/nginx/mylar.access.log;
    error_log /var/log/nginx/mylar.error.log;
  } 
Crowley007 commented 4 years ago

Yes I'm quite sure there are no port conflicts. I use nginx so I only need to open one port to the outside and do use port 9000 in this example. Everything else works just fine on my setup (sonarr, radarr etc.)

So I have mylar running localhost:8090/mylar and reverse proxy it to localhost:9000/mylar. Both are accessible, but settings will not save when connecting through reverse proxy.

And yes I have added http_root and I tried adding those lines in my nginx conf but it still wont work. To confirm, can you save settings through reverse proxy? I can browse and do some stuff just fine, only saving settings wont work.

barbequesauce commented 4 years ago

Yes...

Crowley007 commented 4 years ago

Well then it has to be my setup, but I have no idea what I could do to fix it, I have tried everything I can think of.

barbequesauce commented 4 years ago

Anything pertinent in the nginx access or error logs? Or the Mylar logs? How about the browser javascript console?

Crowley007 commented 4 years ago

Nothing in nginx logs I could see, but the browser console does throw errors:

This when browsing around:

config:447 GET http://192.168.1.100:9000/mylar/interfaces/default/images/successs.png 404 (Not Found)

And this when pressing save:

jquery-1.7.2.min.js:4 GET http://192.168.1.100:9000/mylar/configUpdate?******really long string of stuff*** 414 (Request-URI Too Large)

So something is clearly wrong with my settings but this goes way over my head.

One thing i find strange: "http://192.168.1.100:9000/mylar" does not connect, but when I add "/" it does. When connecting to http://192.168.1.100:8090/mylar, no such problems.

professionaltart commented 4 years ago

The only thing that won't save is the pre-populated location when I go to run a manual post-process. Which was fine for a long time, but I recently moved the default location to a different drive and it still won't budge until I retype it.

Also, due to ISP settings for a while I had to manually access externally from domain:8443/mylar/home - but now I have access to 443, just domain/mylar is enough to forward it to /mylar/home automatically. I suspected there was something happening with how it handles reverse proxies, or how they handle mylar, but I realised it around the time I no longer needed to worry about it.

If you have the same internal and external ports bound to mylar in nginx, does it still cause issues, or work as expected?

Crowley007 commented 4 years ago

Well everything else works fine with my current setup using non default ports, so mylar will too or then it won't. :)

It works fine locally, remote isn't that critical but would have been nice since I have everything else setup that way. And If I really wanted I could just open another port for mylar.

Like I said, my understanding is pretty limited but I also suspect that mylar does something differently with url base, I remember having similar issues with some software before they added url base option. But that's just my uneducated guess.

barbequesauce commented 4 years ago

Just rereading this. Are nginx & mylar on the same box? If so, what's the reason for introducing nginx to the mix?

Can you post your full nginx config + any included configs?

Crowley007 commented 4 years ago

Yeah, everything is running on my home server. I have a web front-end through which I connect to everything. This is where I use nginx and for auth and security, I also only need to open a single port to the outside.

Sure I can post my config, it's probably not clean, but it's what I got to work. I have 2 servers, one for local access and another for remote with ssl etc.

Please let me know when you have taken a look, I'll remove the attachment (removed)

.

barbequesauce commented 4 years ago

So one thing that jumps out -

proxy_pass http://127.0.0.1:8090

I would have made this:

proxy_pass http://127.0.0.1:8090/mylar

as that's what mylar is expecting (based on what you'd indicated the http_root setting is set to). NGINX will pass along the same URL suffix (everything following what you have in the location line) to what you put in the proxy_pass line.

Crowley007 commented 4 years ago

I have tried that and every combination of with slashes and without.

But that actually makes it worse, with that I can't connect to "http://192.168.1.100:9000/mylar/" I have to add /home

Edit: And of course it wont solve the original problem

barbequesauce commented 4 years ago

can you post your nginx access & error logs please?

Crowley007 commented 4 years ago

Error log is empty, this is access log when I navigate to settings and press save.

mylar.access.log

I do appreciate the support, but I'm starting to accept that I will not get this to work like I would want.

barbequesauce commented 4 years ago

Everything in there is a 200 (HTTP success) except the first line, which is a 302 (redirect) - that's normal, CherryPy does that to move you to /home.

I think the focus needs to be on that 414 error from your js console... a little googling gets me to this. What was the use case for adding that to your NGINX config? I don't have it defined in mine...

You also have a very low setting for large_client_header_buffers - the default is 4 8k, yours is 2 1k. Try comment that if the above doesn't fix it.

Crowley007 commented 4 years ago

I also use nginx to serve files, those are just "optimizations" I read somewhere.

But, changing large_client_header_buffers seems to have fixed it! I had no idea it could be something like that.

I have to do some testing, but It seems to be fixed! Thank you!

Crowley007 commented 4 years ago

The local portion on 9000 works now, but remote throws mixed content errors. Well, perhaps google will help with the rest.

professionaltart commented 4 years ago

Just to clarify, sorry, have you tried changing the internal port for mylar to match the external port, within mylar's settings?

Crowley007 commented 4 years ago

No, that would no work for me. I have two servers in nginx, one with port 9000 with no security I use from lan, and one with SSL I use from the outside with a different port.

The original problem of settings not being saved through reverse proxy was fixed by fixing my settings, this mixed content thing is probably something else entirely, probably a symptom of my setup getting too complicated for me.