Setupu Ntfy.sh
A server to send notifications triggered by time, events, etc from your various systems.
What you'll need
- Docker-CE
- Docker-Compose
- (Optional but recommended) A domain name with an A-record pointed to your public IP
- (Optional but recommended) NGinX Proxy Manager, or reverse proxy of your choice
- About 20 minutes of your time
Installation of Docker-CE, Docker-Compose, and NGinX Proxy Manager via a Simple Script
You can easily install Docker-CE, Docker-Compose, Portainer-CE, and NGinX Proxy manager by using this quick install script I created and maintain on Github. Just use the command:
wget -O install-docker.sh https://gitlab.com/bmcgonag/docker_installs/-/raw/main/install_docker_nproxyman.sh
To download the script to your desired host.
Change the permissions to make the script executable:
chmod +x ./install_docker.sh
and then run the script with the command:
./install_docker.sh
When run, the script will prompt you to select your host operating system, then will ask you which bits of software you want to install.
Simply enter 'y' for each thing you want to install.
At some point, you may be asked for your super user (sudo) password as well.
Allow the script to complete installation.
At this point, you might want to log out and back in, as this will allow you to use the docker
and docker-compose
commands without the need of sudo in front of them.
Install Ntfy.sh Using Docker:
Create a new folder inside your parent docker folder. mkdir -p docker/ntfy-server
Move into the new foldercd docker/ntfy-server
Create a new file called "docker-compose.yml" in this foldernano docker-compose.yml
Paste the following code-block into that folder:
version: "2.3"
services:
ntfy:
image: binwiederhier/ntfy
container_name: ntfy-server
command:
- serve
environment:
- TZ=America/Chicago # optional: set desired timezone
volumes:
- ./var/cache/ntfy:/var/cache/ntfy
- ./etc/ntfy:/etc/ntfy
ports:
- 8150:80
healthcheck: # optional: remember to adapt the host:port to your environment
test: ["CMD-SHELL", "wget -q --tries=1 http://localhost:8150/v1/health -O - | grep -Eo '\"healthy\"\\s*:\\s*true' || exit 1"]
interval: 60s
timeout: 10s
retries: 3
start_period: 40s
restart: unless-stopped
Save the file with CTRL + O, press Enter to confirm. Check over the file contents once more to make sure you've adjusted parameters appropriately for your system, then exit the nano text editor with CTRL + X.
Now, run the file with the command
docker compose up -d && docker compose logs -f
In the above command combination, we have 2 commands separated by the ‘&&’ symbol, which means run the second command as soon as the first command completes.
docker compose up -d
says, pull down the images, and start the container running according to the parameters provided in my docker-compose.yml file.
docker compose logs -f
says, show me the running log output of the container as it's being brought up and running.
You can stop seeing the logs at any time by using the CTRL + C hotkey combination.
After the site is up and running, you'll likely want to add a domain name to it.
You'll need to own the domain name, and be able to set the A-record (or a CNAME) for it to point to your public IP. Then you can use a reverse proxy to get the Domain to your server, and get an SSL certificate for https.
This is important if you want push notifications to remotely work for an iOS device.
Once you've setup your reverse proxy and everything is working, you'll need to add a server.yml file to your setup.
You'll want to add a file to the folder that is created here:
~/docker/ntfy-server/etc/ntfy/
called server.yml
nano ~/docker/ntfy-server/etc/ntfy/server.yml
The contents shoudl be
base-url: "https://ntfyserv.youdomain.com"
upstream-base-url: "https://ntfy.sh"
attachment-cache-dir: "/home/youruser/docker/ntfy-server/var/cache/ntfy/attachments"
The base-url needs to match the url you set for your server, and match the url you enter as the default server in the iOS app.
The upstream-base-url needs to be “https://ntfy.sh”, even if you host your own server.
Save the file, and do the following commands:
docker compose down
docker compose up -d
Now publish a message to your server, either through the web interface, or through a command line command.
Subscribe to the topic on your server web ui and your mobile device.
You should receive the message you publish.
Now, you should also be able to post / put to your server from other devices. You can try it out from the command line using curl
.
the -d
option for curl
will do a post / put to an API endpoint. The -L
option tells the curl
command to follow the redirects to our SSL encrypted page. So we can use a command like:
curl -d “Some kind of useful test message here” -L https://myserver.mydomain.com/myTopic
You should then receive the message on any device you have subscribed to “myTopic”.
The format for the curl command is:
curl [option -d] “message text” [option -L] https://yourserver.url/<topic-name>
Support My Channel and Content
Support my Channel and ongoing efforts through Patreon:
https://www.patreon.com/awesomeopensource