Score:0

nginx logging (111: connection refused) when connecting to a websocket

ma flag

So I have a small Raspberry Pi on my local network that I use to host a server. It is a fairly simple setup, with nginx and my npm-hosted server stood up in containers using docker-compose.

my npm server listens to port 30000.

Here is my nginx setup

   server {
        # Listen on port 80
        listen 80;
        listen [::]:80;
    
        # Sets the Max Upload size to 100 MB
        client_max_body_size 100M;

        # Enable compression
        gzip on;
        gzip_disable "MSIE [1-6]\.";

        gzip_comp_level 6;
        gzip_min_length 1024;
        gzip_buffers 16 8k;
        gzip_proxied any;
        gzip_types
            <a bunch of gzip types>

        # Proxy Requests to server
        location / {
    
            # Set proxy headers
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
    
            # These are important to support WebSockets
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
    
            # Make sure to set your port number
            proxy_pass http://npmServer:30000;
        }
    }

When I am serving static content I have no problem. But when I am trying to connect to ws://<PiIP>/socket.io/... I get a connection failed message in my browser terminal, and when I check my logs in docker compose, I see a bunch of connect() failed (111: Connection Refused) errors.

Is there a way to add a socket.io location somehow? I have even spoken to some folks who are hosting the same npm-based project using the exact same setup, and they also have no idea what is going on.

Jaromanda X avatar
ru flag
I take it the npm server in the docker container expects `/socket.io` in the path for `ws` connections?
Flotolk avatar
ma flag
Yes @JaromandaX But just making a /socket.io location causes an error when starting up nginx. I am assuming it does not like the period.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.