mirror of
https://github.com/healthchecks/healthchecks.git
synced 2026-04-25 23:15:49 +03:00
[GH-ISSUE #1091] Consider allowing SITE_ROOT to be used to configure "base path" as well #758
Labels
No labels
bug
bug
bug
feature
good-first-issue
new integration
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/healthchecks#758
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @chrishoage on GitHub (Nov 28, 2024).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/1091
I would like to host healthchecks at
example.com/healthchecksI initially thought
SITE_ROOTwould allow for this, however in realitySITE_ROOTis more likeSITE_ORIGINPlease consider allowing for
SITE_ROOT=https://example.com/healthcheckswhich would configure the routes to use/heathchecks(or whatever the user configured). Alternatively a new config option could be added:BASE_PATHwhere it can default to/and be configured to the user. In both cases this config would likely need to be communicated to the UI in order to construct links and properly load assets.If this request is out of scope for this project then please consider clarifying in the documentation that
SITE_ROOTcan only be used for configuring the origin of the URL, not the full root of the hosted instance as it was not initially clear I couldn't configure the full "root" I wanted using this config option.@cuu508 commented on GitHub (Dec 3, 2024):
Thanks for the suggestion @chrishoage! I updated docs to say
SITE_ROOTis only used for formatting absolute URLs, and serving on a subpath is not tested and not documented.@chrishoage commented on GitHub (Dec 3, 2024):
Thank you!
I was unaware of
SCRIPT_NAME/FORCE_SCRIPT_NAME(I'm just generally unfamiliar with django). I'll give that a shot!I received some more comments in my email that I don't see here, I presume they were deleted.
I am running healthchecks in a docker container though a caddy proxy. I protect my "admin" services (of which I consider healthchecks one of) though Authelia under a special sub domain, which is why I was trying to see if SITE_ROOT would let me specify a sub path.
Much appreciated for the documentation update, and thank you for having healthchecks be selfhost-able!
@chrishoage commented on GitHub (Dec 4, 2024):
To any future google spelunkers who may come across this - it is possible to make this work!
Steps:
That should be all that is required to make this function.
Notes
I am using REMOTE_USER_HEADER and Authelia - I have no idea if the above methods allow login to work. YMMV
In order for this to be "officially supported" (ideally users wouldn't need to strip the path before feeding it downstream) by a
BASE_PATHconfig inlocal_settings.pythe following would need to happenFORCE_SCRIPT_NAME,STATIC_URLandPING_ENDPOINTbased on aBASE_PATHvalue. This could likely default to/to make life easyhc/urls.pyto "re-parent" the routes.path(BASE_PATH, urlpatterns),perhaps, that's just a guess (never worked with Django)If someone enterprising enough wishes to open a PR it sounds like this project may accept it. However since I was able to make this function enough for my own use, I'm happy with the solution I landed at above.
Huge thanks to @cuu508 for the nudges that led me to be able to google what I needed to know to make the above work.
@cuu508 commented on GitHub (Dec 4, 2024):
Yes, I was (and still am) going forth and back between whether I want to spend effort on this or not.
@cuu508 commented on GitHub (Dec 4, 2024):
@chrishoage I pushed experimental changes that should allow Healthchecks to run on a subpath just by setting
SITE_ROOT(as environment variable, setting it in local_settings.py will not work!).I also published a docker image, tagged "master" (temporary, for testing only). I tested the image like so:
uwsgi inside the container runs on port 8000 (this is not affected by
SITE_ROOT), and the above command exposes port 8000. So with this running, I visited http://localhost:8000/healthchecks/ and the login page loaded up.Outside docker, I have nginx running, with the following minimal nginx.conf:
I visited http://localhost/healthchecks/ and the login page loaded up via nginx also.
If you get a chance, perhaps you could test this image as well?
@chrishoage commented on GitHub (Dec 5, 2024):
@cuu508 following your example (adapted for my Caddy and Docker Compose setup) I am able to get a sub path to work by simply supplying
SITE_ROOT!For you to see, here is what I have
In my testing, this works great! (honestly the workaround you pointed me to above was also functioning, but I'll never say no to first class support for the feature!)
Please let me know if I can help any further!
@cuu508 commented on GitHub (Dec 9, 2024):
I've published v3.8. It has the support for path in SITE_ROOT, and has a few additional fixes related to serving Healthchecks on a path:
I've now also removed the temporary image tagged as "master" from Docker Hub.
@chrishoage commented on GitHub (Dec 16, 2024):
I went to update today to pull in these changes but I am no longer able to make it work.
I end up with the application thinking I'm loading
http://healthchecks:8000/checks/checkswhen curlinghttp://healthchecks:8000/checksexample (I am using the linuxserver docker image, but when I started having problems I switched back to the one distributed from this repo, and I have the same behavior):
Strangely however, the actual debug logs show
For now I've gone back to the solution outlined in https://github.com/healthchecks/healthchecks/issues/1091#issuecomment-2516087227 which is working for me. However I think the last round of changes after I left my message may have broken something, as I am no longer able to make it work with the config outlined in https://github.com/healthchecks/healthchecks/issues/1091#issuecomment-2518991756
@cuu508 commented on GitHub (Dec 16, 2024):
@chrishoage did you pass
SITE_ROOTas an environment variable to the container?Specifying it in local_settings.py does not work, because uWSGI also needs to access it.
Here's how I intended it to work:
The linuxserver image doesn't have the SCRIPT_NAME and PATH_INFO patching bits in their uwsgi.ini so I would not expect it to work.
@chrishoage commented on GitHub (Dec 16, 2024):
I tried to reproduce the behavior I was seeing on a different host and it was indeed working.
I think my issue was I had an outdated image on my production host. While at the time I thought I had pulled I obviously didn't, so must have been running an outdated image of
healthchecks/healthchecks:latestAfter pulling
healthchecks/healthchecks:latestI am no longer able to reproduce. I will use this image from now on - thank you!I apologize for the trouble!