2024-08-19 - websockets reverse proxy with nginx

recently i bought Voron 2.4 350x350mm kit from LDO, took a week off from work and started assembly. that felt awesome – sth like lego bricks for adults. :D but that's a story for another day. in order to make sure i not only understand the whole mechanics and wiring, but also the software side i've decided to prepare my own setup for these.

since the stack differs significantly from good old marlin i'm used to, i had to familiarize myself with: klipper, moonraker, fluidd, etc… i've put up Voron stuff repo on GH, to stockpile all configs, mods, etc. again – story for a different day.

today i'll just describe sth that took ~1-2h of my time, trying to understand why i cannot connect with fluidd to moonraker for a long time… with a help of developers tools in the browser i've realized that the connection is done using websockets (ws://foo.bar). for security reasons i used nginx as a reverse proxy (HTTPS, perfect forward secrecy, etc.) for both… and it turned out that websockets are not forwarded with a regular, default RE config:

    location / {
        proxy_pass http://moonraker:7125; # DNS from docker
    }

TL;DR the missing part was explicit websocket forward via:

    location /websocket {
        proxy_pass http://moonraker:7125;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;
    }

on top of that make sure that large files can be transferred (read: g-code files):

    client_max_body_size 1024M;

with these changes it all worked like a charm! :) sth worth remembering for the future, for sure. you're welcome. ;)

blog/2024/08/19/2024-08-19_-_websockets_reverse_proxy_with_nginx.txt · Last modified: 2024/08/19 07:00 by basz
Back to top
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0