muesli / beehive

A flexible event/agent & automation system with lots of bees 🐝
GNU Affero General Public License v3.0
6.32k stars 325 forks source link

Bug: Can't run Beehive behind Nginx under a subdirectory #263

Open sbrl opened 5 years ago

sbrl commented 5 years ago

It doesn't appear to be possible to reverse-proxy Beehive to be served from a subdirectory.

Beehive seems to be absolutely adamant that it's going to request assets from /assets/example.txt instead of /beehive/assets/example.txt - despite me using -canonicalurl.

I've tried both -canonicalurl http://example.com/beehive/ and -canonicalurl http://[::1]:3070/beehive/ - and neither have had any effect.

I'm reverse-proxying with nginx:

location /beehive {
    proxy_pass http://[::1]:3070;
}

Full command line for Beehive: /srv/beehive/beehive -bind [::1]:3070 -config /srv/beehive/beehive.conf -canonicalurl http://subdomain.example.com/beehive/

This appears to be related to #250.

sant-sh commented 5 years ago

Even for me on sub domain under root directory is falling,

Docker command docker run --name bh --restart always -e CANONICAL_URL="http://app.example.com" -d -p 8181:8181 fribbledom/beehive

Nginx reverse proxy `server { listen 80; server_name app.example.com;

location / { proxy_pass http://localhost:8181; } }`

Am I doing any mistakes here?

muesli commented 5 years ago

@sant-sh You need to specify the port in the CANONICAL_URL.

sant-sh commented 5 years ago

@sant-sh You need to specify the port in the CANONICAL_URL.

Thank you for your reply,

I am using cloudflare https on subdomain and passing the traffic through 80 using reverse proxy to the docker port 8181.

So I have tried all the combination but still it failed, here are my combinations, -e CANONICAL_URL="http://app.example.com:80" -e CANONICAL_URL="http://app.example.com:8181" -e CANONICAL_URL="https://app.example.com:443"

muesli commented 5 years ago

@sant-sh Ok, I see. The purpose of CANONICAL_URL is to make sure the web interface knows how to reach its own API. Just set it to whatever URL Beehive can be accessed with. So your initial Docker command doesn't actually look wrong. Did you check what happens when you try and access http://app.example.com? Does it return anything but then fails to access its own API?

sant-sh commented 5 years ago

Its a blank page, nothing comes on screen.

on the docker logs, this is what I see, INFO[0297] Handling request Method=GET URL=/ INFO[0297] serving config/index.html ... (from ) INFO[0297] Finished request Duration=76.48506ms Method=GET Response=200 URL=/ Page source: https://pastebin.com/dbpQCFE9

As I said earlier, I am using cloudflare's dynamic SSL (proxies) which is coming to Nginx subdomain handled by reverse proxy on the exposed port of docker 8181.

Today I have removed cloudflare SSL and just allowed DNS to pass so that I can directly access server's IP on http://app.example.com. CMD: docker run --name bh --restart always -e CANONICAL_URL="http://app.example.com:80" -d -p 8181:8181 fribbledom/beehive

But still page is not loading, I am just getting blank page.

sant-sh commented 5 years ago

Hey @muesli

I don't want to sound pushy, but just wanted to know if there is any solution for this issue or is that I am doing something wrong.

sbrl commented 5 years ago

Have you tried ti without docker, @sant-sh?

sant-sh commented 5 years ago

@sbrl, just now tried, locally it worked on localhost but on Nginx reverse proxy its simple showing as blank (similar to docker).

Is there any specific configuration for Nginx which i should be using?

This is the configurations i am using, location / { proxy_pass http://localhost:8181; }

sbrl commented 5 years ago

Ah, I see. I'm not sure what to suggest.

muesli commented 4 years ago

@sant-sh I just verified the behavior is still working as expected. This definitely works here:

docker run --name beehive -d -e CANONICAL_URL="http://192.168.0.2:8181" -p 8181:8181 fribbledom/beehive

I can then reach Beehive at http://192.168.0.2:8181

sant-sh commented 4 years ago

@muesli my docker instance is behind nginx reverse proxy. So when I am trying CANONICAL_URL="http://api.example.com:8181" it does not work.

I have tested this on my macbook on docker where it works on localhost:8181 but if i use reverse proxy to some different domain then again page fails to load.

sant-sh commented 4 years ago

Finally I got it, port should not passed in canonical_url as beehive looks for exact url.

This command should be used when using any type of proxy docker run --name beehive -d -e CANONICAL_URL="https://beehive.example.com" -p 8181:8181 fribbledom/beehive

@muesli Is there any authentication available for the GUI?

sbrl commented 4 years ago

@sant-sh I believe you need to do that yourself via Nginx. Try looking up the auth_basic directive with HTTPS.

sant-sh commented 4 years ago

@sbrl that is what I was looking for, thanks for the info and help :)