Skip to content

Instantly share code, notes, and snippets.

@spiritualized
Last active March 2, 2024 06:56
Show Gist options
  • Save spiritualized/f86cb05a11af83942ea30bd7cbac29c9 to your computer and use it in GitHub Desktop.
Save spiritualized/f86cb05a11af83942ea30bd7cbac29c9 to your computer and use it in GitHub Desktop.
Uptime Kuma reverse proxy nginx config for a URL prefix
# 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"';
}
@drushadrusha
Copy link

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 change sub_ to subs_ in config.

    # Sub filters to replace hardcoded paths
    proxy_set_header Accept-Encoding "";
    subs_filter_types *;
    subs_filter '/assets/' '/$url_prefix/assets/';
    subs_filter '"assets/' '"$url_prefix/assets/';
    subs_filter '/dashboard' '/$url_prefix/dashboard';
    subs_filter '"/socket.io"' '"/$url_prefix/socket.io"';

    subs_filter '"/icon.svg"' '"/$url_prefix/icon.svg"';
    subs_filter '"/favicon.ico"' '"/$url_prefix/favicon.ico"';
    subs_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