Multi-Site Django Hosting

Well, to save you the trouble, it, in fact, will not do the rest. You need to edit settings related to static files to use that path explicitly, and your reverse proxy needs to be made aware of this change. On top of this, for some bloody reason, Django doubles up the path you set when actually running it, turning “127.0.0.1/coolsite2” to “127.0.0.1/coolsite2/coolsite2”.

tags:
  - "traefik.http.routers.gunicorn-${SITE_NAME}.rule=Host(`localhost`)"
    # bring on the needless complexity!
  - "traefik.http.routers.gunicorn-${SITE_NAME}.rule=PathPrefix(`/${SITE_NAME}`)"
    # strip the path away and continue
  - "traefik.http.routers.gunicorn-${SITE_NAME}.middlewares=gunicorn-${SITE_NAME}-stripprefix"
  - "traefik.http.middlewares.gunicorn-${GROUP_NAME}-stripprefix.stripprefix.prefixes=/${SITE_NAME}"

However, I can code. So I wrote a Python-based Docker Compose wrapper to simplify this. I now have a few lines that I have to just copy and paste into my Django project’s settings.py file, run a handful of simple commands, and boom, it’s done, all on my own self-hosted hardware.


Posted

in