Last active
March 2, 2024 06:56
-
-
Save spiritualized/f86cb05a11af83942ea30bd7cbac29c9 to your computer and use it in GitHub Desktop.
Uptime Kuma reverse proxy nginx config for a URL prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nginx configuration snippet for running Uptime Kuma on a URL prefix | |
# set up for yourdomain.com/kuma, with traffic forwarded to a docker | |
# container with the hostname 'uptime-kuma' | |
# Use docker's DNS | |
resolver 127.0.0.11; | |
# uptime kuma | |
location /uptime { | |
# Define upstream address | |
set $upstream_app uptime-kuma; | |
set $url_prefix uptime; | |
proxy_pass http://$upstream_app:3001; | |
# Set proxy headers | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header X-Forwarded-Protocol $scheme; | |
proxy_set_header X-Forwarded-Host $http_host; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
proxy_buffering off; | |
# Redirect location headers | |
proxy_redirect ^ /$url_prefix; | |
proxy_redirect /dashboard /$url_prefix/dashboard; | |
# Remove URL prefix to pass to the app | |
rewrite ^/uptime/?(.*)$ /$1 break; | |
# Sub filters to replace hardcoded paths | |
proxy_set_header Accept-Encoding ""; | |
sub_filter_once off; | |
sub_filter_types *; | |
sub_filter '/assets/' '/$url_prefix/assets/'; | |
sub_filter '"assets/' '"$url_prefix/assets/'; | |
sub_filter '/dashboard' '/$url_prefix/dashboard'; | |
sub_filter '"/socket.io"' '"/$url_prefix/socket.io"'; | |
sub_filter '"/icon.svg"' '"/$url_prefix/icon.svg"'; | |
sub_filter '"/favicon.ico"' '"/$url_prefix/favicon.ico"'; | |
sub_filter '"/manifest.json"' '"/$url_prefix/manifest.json"'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!
My nginx is not configured with
--with-http_sub_module
, so this is for anyone else who has encountered this problem:Install
libnginx-mod-http-subs-filter
and make sure it's enabled in nginx config.apt install libnginx-mod-http-subs-filter
And remove
sub_filer_once off
and changesub_
tosubs_
in config.