New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Host in a subfolder / different root path #186
Comments
Hmmmm. It definitely seems like this should be easier than all that. I will take a look at this soonish. In the mean time, is a subdomain not an option you could use? |
Well, if you want to e.g. host locally on a Raspberry for privacy reasons, you'd have http://raspberrypi.local and it's hard to setup a subdomain. But you might want to host multiple services, so a subfolder seems the natural choice (at least to me…) |
True. But in that case you could also just assign any other local domain you want to the Pi (in additional to the default one) — e.g. babybuddy.local. Regardless, I’m not judging your choice here (: Just not sure when I’ll get a chance to test this. |
I found some other places in the code where the path is hardcoded:
|
I finally did a bit of research on this and surprisingly it does not seem to be well supported at all by Django. You seem to be on the right path. With your settings, could you test using |
Yes, this works for the templates, thank you very much! But one thing remains, the https://github.com/babybuddy/babybuddy/blob/master/babybuddy/static_src/root/site.webmanifest.json . Since it's static I guess it will be impossible to influence? I'd put up a PR otherwise. Also it seems I have to correct my earlier statement a bit and one line has to be
(not |
Or can you give me a good advice, how to flush all caches and generated static files? |
Are that and https://github.com/babybuddy/babybuddy/blob/master/babybuddy/static_src/root/browserconfig.xml the only static files that specify the root path? If so your best bet may be to just manually modify them if your deployment method supports that. The annoying reason that I commit static assets is generating them requires a lot of extra dependencies (node, gulp, node-sass, and on and on and on). If you want to take a stab at doing it that way you’d need to setup a development environment (see https://github.com/babybuddy/babybuddy/blob/master/CONTRIBUTING.md#development) and then you’d have to take a look at the whitenoise documentation to see if it can support your use case — I think it can but I’m not 100% sure (see http://whitenoise.evans.io/en/stable/django.html#WHITENOISE_STATIC_PREFIX). Neither option is particularly good 😕 |
This is rather vaguely related, but I figured I'd leave it here for others with a similar problem I wanted to host babybuddy as one among many on a small homeserver and stumbled upon similar problems. What seems to work is:
So the user can initially browse to If somebody wants to do this based on Traefik with BabyBuddy running in a docker container, this should get you started:
labels:
# route all requests starting with "/babybuddy" here
- "traefik.http.routers.babybuddy.rule=PathPrefix(`/babybuddy`)"
# use middlewares for stripping the "/babybuddy"-path from url and then redirect to correct port
- "traefik.http.routers.babybuddy.middlewares=strip_babybuddy_prefix@file,redirect_babybuddy_to_port@file"
[http.middlewares]
# remove "/babybuddy" from URL before actually routing to babybuddy
[http.middlewares.strip_babybuddy_prefix.StripPrefix]
Prefixes = "/babybuddy"
# remove "/babybuddy" from URL before actually routing to babybuddy
[http.middlewares.redirect_babybuddy_to_port.redirectScheme]
scheme = "http"
port = 4242 Make sure to set the scheme to |
I also looked a bit into this and have identified three templates that I needed to adjust to work on my side, namely:
The other changes that I did were all in the base settings file (btw: the LSIO docker file does not respect the DJANGO_SETTINGS_MODULE environment variable, it always sets it to the base file), namely changing "/login/" to "login/" and "/static/" to "static/" as well. I currently don't have a proper testing setup, but if there is the need, I could set it up and create a pull request, or is all the testing done when a PR is created anyways? |
@MagiX13 yeah tests will run on PR -- you don't need to worry about that. And if I think any tests need to be added for this feature I can chip in. |
If you have some pointers on how to avoid another entry for static/babybuddy please let me know. Django static files and me are not on good footing. |
@MagiX13 Sorry I’m a little lost here — what’s the current state with your PR? Ideally we should add some documentation for this as well. I’m unclear how to set this up myself for testing. |
@cdubz Fully understand that. I did some more testing and it seems to work on my end, but I would be happy to add some documentation, I guess this goes into the Deployment documentation? I'm using gunicorn and nginx and the relevant nginx lines look like this:
Thus the babybuddy works via nginx under |
@MagiX13 yeah lets get some documentation on #358 branch. I actually tried to get this working for testing yesterday based on this issue and that PR but couldn't get it working. Also note there is a |
We have full support for subdirectory hosting now, at least for the example uWSGI + NGINX deployment method. See https://docs.baby-buddy.net/setup/subdirectory/ for details! Happy to add other information for different deployment configurations if people have use cases to share. |
Hello, i'm using nginx proxy manager docker to host all my home sites behind an https nginx proxy What i'm failing to understand is whether the docker-compose.yml file would need the SUBPATH=/bb/ or not (it doesn't seems so) and whether
is sufficient or i'm missing something. If i do what i wrote above i get Some content seems to load fine though but it feels like babybuddy docker is still looking for the root path |
@maxdd I'm not sure what the best approach is for that situation. LSIO has a couple of support options you may want to try checking out: https://www.linuxserver.io/support |
Are you suggesting that this is docker related and that adding SUBPATH + a proxy pass on a frontend nginx (not the one used by babybuddy) is sufficient? |
Hey, just randomly saw this in my feed. I had some issues with hosting babybuddy on a subfolder as well but managed since a year or so to have it work reliably. However, I am using apache, but I think the config is easy to translate to nginx! Apache configuration for hosting on
|
The issue is that I use nginx as a reverse proxy on a different docker so it doesn't have knowledge of /var/local/babybuddy/media/ Your docker image seems like a local build, are
present in the standard linuxserver version? |
Good point, I forgot about that. Yes, I had to modify my docker-build a bit. My main-addition is configuring a new default django-settings file: $ cat ./root/app/babybuddy/babybuddy/settings/docker.py
from .base import *
import os
FORCE_SCRIPT_NAME = os.environ.get("FORCE_SCRIPT_NAME", None)
if not FORCE_SCRIPT_NAME:
del FORCE_SCRIPT_NAME
if os.environ.get("USE_X_FORWARDED_HOST", "False").lower().strip() == "true":
USE_X_FORWARDED_HOST = True So you did sniff this out correctly. I branched off at tag |
This is still important if you want to set debug=False (which generally is advised for production environments). When not in debug-mode, django will not serve static files or media files. The media-files live on the "outside" of docker in my case (the config-directory) so I need to serve them by some other means. |
Hi,
instead of hosting on the root of a domain (like
https://example.com/
), I wanted to host babybuddy in a different path likehttps://example.com/examplepath
.I was able to almost fully achieve it by setting
at the end of
production.py
.There are only two minor glitches: All functionality and links work nicely, with the exception of the textual "Home" link and the link on the Babybuddy logo, which leads to https://example.com/ instead of https://example.com/examplepath/
What would be the best way to add that last bit of functionality?
path('', ?, name='home'),
at https://github.com/babybuddy/babybuddy/blob/master/core/urls.py#L9href="/"
at https://github.com/babybuddy/babybuddy/blob/master/babybuddy/templates/babybuddy/nav-dropdown.html#L6 and https://github.com/babybuddy/babybuddy/blob/master/babybuddy/templates/babybuddy/base.html#L36?
I'm unfortunately not very literate in Python, otherwise I would have tried myself. But if you can give me some hints in the right direction, I'd put up a PR for it.
The text was updated successfully, but these errors were encountered: