I’m playing around with my own instance of Lemmy but I keep getting a “websocket connection failed” error in my console. I’m having a really hard time understanding how to set up nginx for websockets - I’m more used to Apache and not familiar with WS at all. Is there documentation hiding somewhere that will help me set up my proxy forwarding properly?

EDIT: Solved! Check out my solution here: https://lemmy.world/comment/141648. Thanks everyone!

  • ubergeek77
    link
    fedilink
    English
    31 year ago

    If you’re willing to use Caddy instead, it’s infinitely easier. Websockets is just enabled by default, no shenanigans. Here is an example Caddyfile to use in a Docker deployment (but you can change those http urls to point to localhost for a non Docker deployment):

    (caddy-common) {
        encode gzip
        header {
            -Server
            Strict-Transport-Security "max-age=31536000; include-subdomains;"
            X-XSS-Protection "1; mode=block"
            X-Frame-Options "DENY"
            X-Content-Type-Options nosniff
            Referrer-Policy  no-referrer-when-downgrade
            X-Robots-Tag "none"
        }
    }
    
    your.lemmy.url {
        import caddy-common
        reverse_proxy   http://lemmy-ui:1234
    
        @lemmy {
            path    /api/*
            path    /pictrs/*
            path    /feeds/*
            path    /nodeinfo/*
            path    /.well-known/*
        }
    
        @lemmy-hdr {
            header Accept application/*
        }
    
        handle @lemmy {
            reverse_proxy   http://lemmy:8536
        }
    
        handle @lemmy-hdr {
            reverse_proxy   http://lemmy:8536
        }
    
        @lemmy-post {
            method POST
        }
    
        handle @lemmy-post {
            reverse_proxy   http://lemmy:8536
        }
    }
    

    Caddy has some great plugins that allow you to automate https certificate renewal too, easy to add to any config.

    I know you asked about nginx and I’m just telling you “haha just switch,” but I had similar headaches with my own deployment when I tried using nginx, and I eventually just gave up and used Caddy. Saved me at least a few hours of headache.

    • @penguin_ex_machinaOP
      link
      English
      11 year ago

      Hmmm I might consider this. I’ll need to look into it more though, I’ve never heard of Caddy before. Thanks for the heads up :D