mirror of
https://github.com/healthchecks/healthchecks.git
synced 2026-04-25 06:55:53 +03:00
[GH-ISSUE #822] Hosting under a subpath does not work well #577
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#577
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 @spantaleev on GitHub (Apr 11, 2023).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/822
I'm trying to host Healthchecks under a subpath like
/healthchecksand I'm using the following configuration:Environment variables:
local_settings.pymounted to/opt/healthchecks/hc/local_settings.pyin the container image:I think that adding
/healthcheckstoSITE_ROOTmay be unnecessary. Perhaps defining theSCRIPT_NAMEenvironment variable does nothing as well.Nevertheless,
FORCE_SCRIPT_NAMEandSTATIC_URLare obeyed.With this configuration, I also needed to configure my reverse-proxy to:
/healthchecks/staticprefix intact/healthchecksprefix from all other (non-static file) requestsWhat works:
/healthchecks/redirects to/healthchecks/accounts/login/, as expected/healthchecks/accounts/login/is rewritten to/accounts/login/by the reverse-proxy and serves a page, as expected/healthecksprefix, as expected/healthecksprefix, as expected. If I hadn't redefinedSTATIC_URLwith my customlocal_settings.pyfile, this wouldn't have been the case./healthchecks/static/CACHE/css/output.c2fb96c40f0a.css) are kept as-is (no stripping of the prefix), and are served, as expected. Note that if we strip the prefix (like we do for other URLs), we'll get 404sWhat doesn't work:
/static/.., not/healthchecks/static/..Because of this, fonts can't load, which breaks various icons and makes the system unusable.
Is there a way to make the generated CSS file actually use relative URLs, not absolute ones? Or to make it obey
STATIC_URL?@cuu508 commented on GitHub (Apr 11, 2023):
As an experiment, I added to my local_settings.py:
I ran
manage.py collectstaticandmanage.py compress.In HTML pages, I now see CSS includes with the /foo/ prefix:
In the CSS file, I see fonts referenced with the
/foo/prefix:One thing to try, if you haven't done it already, is to run
manage.py collectstaticandmanage.py compress.@spantaleev commented on GitHub (Apr 11, 2023):
I haven't tried these. Thanks for the pointers!
This may work, but it's problematic, because:
--read-onlyfilesystem, so these files aren't writable--user=...), so it can't write to these files even if they're not readonlyLooks like solving it this way will require both some hacks (
--entrypoint=/bin/sh+-c "python /opt/healthchecks/manage.py collectstatic --no-input && python /opt/healthchecks/manage.py compress && uwsgi /opt/healthchecks/docker/uwsgi.ini") and also decreasing security.I was considering doing a
sed-replace instead of running thesemanage.pycommands, but.. these files are not writable due to the read-only filesystem anyway, so that's another no-go. Seems like the/opt/healthchecks/static-collectedfiles are allroot:root-owned too.@cuu508 commented on GitHub (Apr 11, 2023):
Looking at django-compressor docs there might be a way to generate relative paths to the font files – use
CssRelativeFilterinstead ofCssAbsoluteFilter. I'll look into that.Assuming relative paths work, I think the prebuilt CSS would work regardless of the STATIC_URL value at runtime.
@cuu508 commented on GitHub (Apr 12, 2023):
I pushed a change which switches CSS bundles from using absolute file paths to using relative file paths.
I'm not planning to do a new release soon, but in the meantime you can build an image yourself: clone the repository and from its root directory run
@spantaleev commented on GitHub (Apr 12, 2023):
Glad to hear that it's fixed! Thank you for fixing it up so quickly!
I have built
mastermanually and tested that it's indeed fixed, so I'm closing this issue.I'm actually hosting Healthchecks without using a subpath, but wanted to have support for this anyway, so that others using the mash-playbok Ansible playbook and its Healthchecks service (powered by the ansible-role-healthchecks Ansible role) can host it at a subpath.
We support hosting at a subpath for various other services, so I thought that supporting it for Healthchecks would be useful to others, as not having to configure DNS for each and every additional service is much more convenient.
Healthchecks support is still a new addition to this Ansible playbook, so if you do give it a try some time and have some feedback about our integration, it'd be great to hear it.