bp2008 / ui3

A powerful, modern HTML5 web interface for Blue Iris.
GNU Lesser General Public License v3.0
124 stars 16 forks source link

Issue hosting Blue Iris under a virtual directory #11

Closed dmadesign closed 4 years ago

dmadesign commented 6 years ago

I followed your instructions on hosting Blue Iris under a virtual directory and I am unable to get it to work. I an able to access Blue Iris if I use a subdomain but I would really like to us a directory instead. I added a screenshot of the error I am seeing below.

image

bp2008 commented 6 years ago

I assume blueiris is supposed to be your virtual directory. It is missing a slash on the end somehow. The path should be blueiris/login.htm, not blueirislogin.htm.

dmadesign commented 6 years ago

The only way I can get the slash between blueiris and login is by adding a slash after blueiris in the virtual box. The closest I can get it to working is if I add a trailing slash after blueiris in the virtual box as well as the location and proxy pass address in NginX. Adding the trailing slash I can get the login page to appear but once I log in I get a 404 error. It looks like the subdirectory is not getting passed? If I then open a new chrome tab and type in mydomain.com/blueiris I am redirected to the UI3 page. Do you have any idea why the subdirectory is not being forwarded?

image image image

bp2008 commented 6 years ago

All I know is it was working for me months ago when I tested not including trailing slashes. I don't have a lot of free time at the moment to try this again.

stk1987 commented 6 years ago

Try to loaded from a older version. To test what version worked. If you need install instructions, see the main readme here: https://github.com/bp2008/ui3

ddebeau commented 6 years ago

I got the following nginx virtual directory configuration to work on UI3 and Android:

BlueIris Virtual Setting: /blue

server { listen 80; listen [::]:80;

server_name nginx.example.com;

location /blue { proxy_pass http://blue.example.com:81; proxy_set_header X-Forwarded-For $remote_addr; proxy_buffering off; }

location /blue/json { proxy_pass http://blue.example.com:81/json; proxy_set_header X-Forwarded-For $remote_addr; proxy_buffering off; }

location /blue/video { proxy_pass http://blue.example.com:81/video; proxy_set_header X-Forwarded-For $remote_addr; proxy_buffering off; }

location /blue/thumbs { proxy_pass http://blue.example.com:81/thumbs; proxy_set_header X-Forwarded-For $remote_addr; proxy_buffering off; }

location /blue/file { proxy_pass http://blue.example.com:81/file; proxy_set_header X-Forwarded-For $remote_addr; proxy_buffering off; }

location /blue/image { proxy_pass http://blue.example.com:81/image; proxy_set_header X-Forwarded-For $remote_addr; proxy_buffering off; }

location /blue/alerts { proxy_pass http://blue.example.com:81/alerts; proxy_set_header X-Forwarded-For $remote_addr; proxy_buffering off; } }

bp2008 commented 6 years ago

That configuration looks fine, though I think you should be able to leave out all but the first location rule.

ddebeau commented 6 years ago

I had to put those in to get it to work. For some reason Blue Iris isn't using the virtual directory setting for everything.

bp2008 commented 6 years ago

Hmm. I haven't gotten around to testing again myself, yet, but I may find time tomorrow.

dmadesign commented 6 years ago

I was also able to make it work by changing the proxy pass location into a subdomain. I was hoping to find a way to keep the proxy pass as a directory. I recently setup cloudflare and with the free account you can only use a first level subdomain, so I am trying to use home as my subdomain for everything, like home.mydomain.com/blueiris for Blue Iris and home.mydomain.com/app1 for app1, etc. I may have to scrap the entire idea as I have been unable to get Blue Iris UI3 to work with cloudflare.

ddebeau commented 6 years ago

I finally got it to work by adding trailing slashes. Each one is important.

location /blue/ { proxy_pass http://example.com:81/; proxy_set_header X-Forwarded-For $remote_addr; proxy_buffering off; }

dmadesign commented 6 years ago

ddebeau,

Is that using a subdomain or were you able to figure out using a subdirectory? Here is how I have it setup now.

    server_name blueiris.mydomain.com;

    location / {
        proxy_pass       http://192.168.1.xxx:81/;
ddebeau commented 6 years ago

The above configuration uses a sub directory. If you use a sub directory make sure to add /subDirectory to Virtual in the Blue Iris Web Server configuration.

davidvermillion commented 5 years ago

I'm having similar issues with getting this to work with a reverse proxy, in this case, apache. Here's my config:

<Location /bi/> Order allow,deny Allow from all ProxyPass http://192.168.1.230:9095/bi/ ProxyPassReverse http://192.168.1.230:9095/bi/

blueirisconfig

blueiriserror

bp2008 commented 5 years ago

I would try changing the "Virtual" string in BI Options to just "/bi".

If that doesn't work, read the "Hosting under a virtual directory" section on this page. https://github.com/bp2008/ui3/wiki/Using-UI3-with-a-reverse-proxy-server

At the end there is a line of code you can insert into a specific file to override the base URL. You can look in chrome developer tools on the Network tab to inspect the outgoing URLs and see what it is trying, if necessary.

samwathegreat commented 4 years ago

Can we re-open this issue?

This is still an issue. Configuring blue iris / ui3 for reverse proxy should be simple, but the virtual directory setting is still not working properly on 4.8.6.3.

First, if you change virtual directory to /bi (without the trailing slashes), ui3 will often forward you to a malformed URL, for example: example.com/bilogin.htm?page=%2Fbi%2Fui3.htm (notice it didn't insert the trailing slash).

If you DO insert the trailing slash in blue iris: virtual directory = /bi/ then it works as intended except for some really annoying quirks specifically involving login and logout.

For example: with virtual directory set to /bi/ and you visit example.com/bi/ it will show the login page correctly -- but when you log in, it redirects you to: https://example.com/?session=089119ad75343e9907d76c39788f4f29

It's completely missing the /bi/

Now after having logged in, if I go BACK to example.com/bi/ it takes me straight into UI3 as I've already logged in. So the redirection appears to be botched in regards to the virtual directory.

Furthermore, it HAD a similar bug when logging out. When logging out of UI3, it was redirecting you back to the login page without the virtual directory in the path -- but this appears to have been fixed when I upgraded to 4.8.6.3 this morning. The LOGIN bug is still present. It simply isn't using the virtual directory entered in the blue iris web server settings.

P.S. I've also tried this with putting the ui3-local-overrides.js script file in the UI3 folder with the contents currentServer.remoteBaseURL = "/bi/";

Still doesn't work.

Please advise. I really need to get this working. It would be EASY for me to use reverse proxy with a subdomain and no virtual directory, but my configuration requires me to use a subdirectory instead. All of my other servers work fine with my nginx reverse proxy using this method.

Your help is much appreciated.

-samwathegreat

samwathegreat commented 4 years ago

Attached is proof of the issue -- chrome developer tools showing that the intitiator /bi/login...... forwarded me to ?session= blah blah blah -- but without the virtual directory in the path.

How can we fix this? My current workaround is that I have to login, then I get forwarded to a non-existent URL, then I type my blue iris server address back in again, and I'm logged in. This 2nd step should not be necessary as UI3 should be automatically forwarding me to the correct location upon login.

blueiris_issue

@bp2008

Please advise.

bp2008 commented 4 years ago

Hi @samwathegreat

I've looked into this issue a bit this morning.

I apologize for this being more complicated than it needs to be. I am very much a third-party developer and have no access to Blue Iris source code. I had nothing to do with the creation of the virtual directory setting and it isn't documented in the help file. Through experimentation, I can tell you that it affects where Blue Iris redirects you to when you load its root path (e.g. http://127.0.0.1/ -> http://127.0.0.1/bi/login.htm). It also makes Blue Iris's web server respond to requests that use that virtual directory in the path, although this is not actually necessary when working with a reverse-proxy server, as such a server would rewrite the paths so that Blue Iris never saw the virtual directory in a path. As far as I can tell, those two things are all it does.

Anyway, the unfortunate fact is, the only way UI3 can learn what the virtual directory path is, is for you to tell it. You did this with the local-overrides script. The login page doesn't load the local overrides script, so for the login page to function properly, you need to open login.htm in a text editor and go to line 320 where it says page = "/"; and change that to page = "/bi/";. Because Blue Iris 4 was discontinued about a year ago, you won't need to worry about any new patches stomping out your change.

It might also be sufficient for you to change your link or bookmark to go directly to UI3 using the correct virtual directory. This way, when necessary you will be redirected to login, but your original path will be preserved via the query string. Then when you log in, you should be returned to the correct path.

samwathegreat commented 4 years ago

@bp2008

Thanks so much for looking into this for me!!

A couple of follow-ups: This still isn't working, as making the recommended modification to the login.htm file now results in being unable to successfully login, receiving the error in the attached screenshot.

Please note that I'm not even using nginx reverse proxy currently while I'm troubleshooting. FIRST, I'm trying to get this fully working inside the local network. So I'm going to: http://blueiris.ip.address:81/bi/

I'm not using the root path at all. I'm always going to blueirisipaddress:81/bi/

I figure once I get it working fully locally using the virtual directory, I'll mess with nginx reverse proxy.

But I can't even manage to get it working using local ip address and virtual directory.

Interestingly, I can not even find the "json" file referenced in the error.

Regarding your last paragraph, this doesn't seem to work for me either. I've already bookmarked using the virtual directory in the path, and upon logging in, it still forwarded me to the non-existent URL.

Modifying the login.htm file as suggested seems to have helped somewhat, as the login page is now correctly forwarding me to the virtual directory, but something is still broken.

Any further ideas?

blueiris_json

ddebeau commented 4 years ago

@samwathegreat

NGINX will modify the location header from the redirect by default when using proxy_pass. You can also set it manually by specifying proxy_redirect. I'd recommend troubleshooting with NGINX because you'll be able to modify the redirects explicitly.

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect

samwathegreat commented 4 years ago

@ddebeau

Thanks for your comments.

The issue I'm having is that I'm already hosting other services on this same domain. So while I'd love to leave blue iris / ui3 alone and have nginx handle everything, I can't figure out how to accomplish it. For instance, my config is set to use my.domain/bi/

I've tried proxy_pass with and without the trailing slash, but the UI3 server has references to / which results in nginx routing those requests to my other server, which is hosted on my.domain/ rather than correctly routing the requests/links to my.domain/bi/

I think you are suggesting that there is a workaround, but I can't wrap my head around it. I've looked over the page you linked, but can't determine a proper solution.

Do you know what I'm missing?

ddebeau commented 4 years ago

@samwathegreat

I'm currently running Blue Iris on its own sub-domain so I don't have an active working configuration for a sub-directory. Since Blue Iris is not adding the virtual directory every time, I would try setting it to the default (/) and do all manipulation in NGINX.

You may have tried something similar to the basic configuration below. proxy_redirect is operating in an equivalent way to proxy_redirect default;. I wrote it explicitly to highlight how it works. Requests to http://my.domain/bi/ are forwarded to http://upstream:port/. Any redirect location headers from http://upstream:port/ that include http://upstream:port/ are replaced with /bi/.

location /bi/ {
    proxy_pass     http://upstream:port/;
    proxy_redirect http://upstream:port/ /bi/;

I'd play around with the redirect settings while checking the 302 redirect location header in Chrome to see what NGINX is doing.

samwathegreat commented 4 years ago

@ddebeau @bp2008

Thanks for the help gentlemen. I found no solution, so I ended up rewriting my infrastructure to support subdomains. Blue Iris 4 virtual directory support clearly doesn't work as intended. It looks like a cookie issue, setting path to /, regardless of how I modified the relevant entry(s) in login.htm.

As expected, it was a simple matter to configure nginx to proxy Blue Iris at bi.my.domain . I would advise against attempting to use a virtual directory with Blue Iris 4.