Skip to content

Apprise behind Caddy reverse proxy with subpath #288

@opelx

Description

@opelx

Question

I am attempting to use Caddy as a reverse proxy to place Apprise on a subpath, meaning that Apprise can then be accessed and managed at example.com/apprise. So far, I have had limited success with this. It appears that Django respects BASE_URL=/apprise, but Apprise does not seem to cooperate well with the bundled NGinx. I have created an override.conf for this.

I am using rootless Quadlets with Podman, which should not be the problem :) The idea is to put signal-api, nfty, and possibly gotify as backends in their own network, which only Apprise has access to and can address via the configs.

So far, the forwarding is working quite well, but the hack of also rewriting /details* /cfg* /status* /health* via Caddy has the unpleasant effect that the web browser's URL now says example.com/details – no more subpath.

Have I misunderstood the BASE_URL=/apprise? Attached are some configuration excerpts. I haven't found any problems with example.com:8008 (Apprise app) using the following settings.

~/.config/containers/systemd/apprise/apprise-api.container

[Container]
Image=docker.io/caronc/apprise:1.3
ContainerName=apprise-api
PublishPort=8008:8000
EnvironmentFile=%h/.config/containers/systemd/apprise/aprise-api.env
Volume=%h/.config/containers/systemd/apprise/conf/subpath-location-override.conf:/etc/nginx/location-override.conf:ro,Z
...

~/.config/containers/systemd/apprise/aprise-api.env

APPRISE_STATEFUL_MODE=simple
APPRISE_ADMIN=yes
BASE_URL=/apprise
STRICT_MODE=yes
...

~/.config/containers/systemd/apprise/conf/subpath-location-override.conf

# Static assets: /apprise/s/* -> /s/*
if ($uri ~ "^/apprise/s/(.*)$") {
    rewrite ^/apprise/s/(.*)$ /s/$1 last;
}

# All other /apprise/* -> stripped prefix
if ($uri ~ "^/apprise/(.*)$") {
    rewrite ^/apprise/(.*)$ /$1 last;
}

~/.config/containers/systemd/caddy/conf/Caddyfile

{
	http_port 8000
    ...
}

http://example.com:8000 {
    redir /apprise /apprise/ # canonical redirect
	@apprise_subpath path /apprise/*
	handle @apprise_subpath {
		uri strip_prefix /apprise
		reverse_proxy apprise-api.dns.podman:8000 {
			import header_common
		}
	}
	# fix for mis-generated absolute URLs
	@apprise_root path /details* /cfg* /status* /health* /
	handle @apprise_root {
		rewrite * /apprise{uri}
		reverse_proxy apprise-api.dns.podman:8000
	}
    # fallback
	handle {
		respond "Caddy Frontend Alive, but SubPath Not Found" 404
	}

	@rootPath {
		path /
	}
	handle @rootPath {
        # dashy
		redir http://example.com:9000
	}
}
...

Note, I'm using nft to forward all traffic at :80 to :8080, where caddy exposes/maps his :8000 port to 8080 on host.

Finally, I would assume, a simple

	handle /apprise/* {
		reverse_proxy apprise-api.dns.podman:8000
	}

would be sufficient by setting BASE_URL=/apprise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions