Skip to content

Running changedetection.io behind a reverse proxy

dgtlmoon edited this page Dec 27, 2023 · 6 revisions

You need to enable the USE_X_SETTINGS environment variable in changedetection.io for it to respect HTTP headers sent from the reverse proxy (such as Host, X-Forwarded-Prefix and X-Forwarded-Proto).

The easiest way is to create an extra docker-compose YML file and run it with the shipped version. Create a docker-compose.nginx.yml (expose may not be what you want, but up to you):

version: '2'
services:
  changedetection.io:
    environment:
      # Respect proxy_pass type settings, `proxy_set_header Host "localhost";` and `proxy_set_header X-Forwarded-Prefix /app;`
      - USE_X_SETTINGS=1
    networks:
      changenet:
        aliases:
           - changedetection-app

  nginx:
    image: nginx:1
    expose:
      - 80
    ports:
      - 80:80
    volumes:
        - ./nginx.conf:/etc/nginx/conf.d/default.conf
    networks:
        changenet:

networks:
  changenet:

NGINX Reverse Proxy

And an example nginx.conf which hosts changedetection on the subdirectory /app:

server {
    listen 80;
    server_name localhost;

    location /app/ {
        proxy_pass http://changedetection-app:5000/;
        proxy_set_header Host "localhost";
        proxy_set_header X-Forwarded-Prefix /app;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

When using a subdirectory, it's important to have a trailing '/' on the location line. Otherwise, static CSS and JS content will not load properly. The trailing slash is not needed when hosting changedetection.io on a subdomain.

Then simply

docker-compose -f docker-compose.yml -f docker-compose.nginx.yml up

The application will be available at http://127.0.0.1/app

Note: You may like to comment out the ports: section of the base docker-compose.yml

      # Comment out ports: when using behind a reverse proxy , enable networks: etc.
      ports:
        - 5000:5000

Apache Reverse Proxy

<Location /changeio>
        RequestHeader set X-Forwarded-Prefix "/changeio"
        ProxyPass "http://location:5000/"
        ProxyPassReverse "http://location:5000/"
</Location>

Caddy Reverse Proxy

In Caddy alternately, you just need to configure the X-Forwarded-Prefix.

Example using yoursite.com/cd as the path

Be sure to also configure the base URL in 'Settings' to https://yoursite.com/cd

yoursite.com {
    rewrite /cd /cd/
    route /cd/* {
        uri strip_prefix /cd
        reverse_proxy changedetection:5000 {
            header_up X-Forwarded-Prefix /cd

# If some CSS or JS doesnt work, try adding a leading / instead
#            header_up X-Forwarded-Prefix /cd/
        }
    }
}

Using Caddy v2 and a subdomain, the configuration is simply

changedetection.yoursite.com {
    reverse_proxy localhost:5000
}

Known Issues

Caddy+Traefik etc - Random problem fetching resources, see https://github.com/dgtlmoon/changedetection.io/issues/2053