Skip to content

Apache reverse proxy

Here are example configurations to set up Apache as a reverse proxy for Notifly.

The following modules are required:

  • mod_proxy
  • mod_proxy_wstunnel
  • mod_proxy_http
<VirtualHost *:80>
ServerName domain.tld
Keepalive On
# The proxy must preserve the host, as notifly checks the host against the origin
# for WebSocket connections
ProxyPreserveHost On
# Proxy websocket requests to /stream
ProxyPass "/stream" ws://127.0.0.1:NOTIFLY_PORT/stream retry=0 timeout=60
# Proxy all other requests to /
ProxyPass "/" http://127.0.0.1:NOTIFLY_PORT/ retry=0 timeout=5
ProxyPassReverse / http://127.0.0.1:NOTIFLY_PORT/
</VirtualHost>
<VirtualHost *:80>
ServerName domain.tld
Keepalive On
Redirect 301 "/notifly" "/notifly/"
# The proxy must preserve the host, as notifly checks the host against the origin
# for WebSocket connections
ProxyPreserveHost On
# Proxy websocket requests to /stream
ProxyPass "/notifly/stream" ws://127.0.0.1:NOTIFLY_PORT/stream retry=0 timeout=60
# Proxy all other requests to /
ProxyPass "/notifly/" http://127.0.0.1:NOTIFLY_PORT/ retry=0 timeout=5
# ^- !!the trailing slash is required!!
ProxyPassReverse /notifly/ http://127.0.0.1:NOTIFLY_PORT/
</VirtualHost>

With certain additional Apache configurations, ProxyPass for the /stream endpoint may not work correctly. The request fails with 400 Bad Request and the following error is written to the Notifly log:

Error #01: websocket: the client is not using the websocket protocol: 'upgrade' token not found in 'Connection' header

To fix this issue, add the following rewrite rule to the virtual host configuration:

RewriteEngine on
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /notifly/stream(.*) ws://127.0.0.1:NOTIFLY_PORT/stream$1 [P,L]