0
submitted 1 year ago* (last edited 1 year ago) by penguin_ex_machina@lemmy.world to c/selfhosted@lemmy.world

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!

you are viewing a single comment's thread
view the rest of the comments
[-] aucubin@lemmy.aucubin.de 0 points 1 year ago* (last edited 1 year ago)

The nginx config provided in the Docker installation part contains everything needed for nginx. If you are installing lemmy directly on the machine you may need to use different upstreams.

The websocket part is basically the

            # proxy common stuff
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";

part in the nginx config on that page.

[-] penguin_ex_machina@lemmy.world 0 points 1 year ago

I seem to be having a lot of lag at the moment, and my post was created twice so I'm just going to delete the other one and start from here...

So I have this set up per the instructions. My instance is on a Digital Ocean instance, and I'm using nginx on the host to point to localhost:1235, but that's about all that conf file is doing. Is there something else I need to do?

[-] aucubin@lemmy.aucubin.de 0 points 1 year ago* (last edited 1 year ago)

Ok, just to understand what you did. You got an Digital Ocean droplet with Docker and used the instructions in the link I posted or different ones?

If you are using the instructions from my link nginx will also run in a docker container, which means that your upstream will not be on localhost, but rather the lemmy and lemmy-ui containers.

If you did install it locally then localhost:1235 could be correct.

[-] penguin_ex_machina@lemmy.world 1 points 1 year ago

I think this is where my lack of experience with Docker is showing.

I spun up a DO droplet and installed nginx, Docker CE, and Docker Compose. Then I went through the instructions on the page you linked to and it set it up just fine but when I went to my droplets IP address it wouldn't connect. I had to add a config file that pointed traffic coming into the droplet on port 80 to redirect to the Docker container instead. Am I overcomplicating it?

[-] aucubin@lemmy.aucubin.de 0 points 1 year ago

No, you are right. If you are using the nginx container from the docker installation guide then you will also need to add port 80 atleast in order to see anything, as nginx will otherwise not listen on the port 80 of the droplet.

How does your nginx.conf look now?

[-] penguin_ex_machina@lemmy.world 0 points 1 year ago

The one meant for the Docker container or the one on the host?

[-] aucubin@lemmy.aucubin.de 0 points 1 year ago

Ah, so you added another nginx on the host by installing it from the package store of the distro and have that proxy port 80 to the docker nginx?

If you do that then you also need to add the websocket settings I had in the first comment to the host nginx.

What I meant what that the nginx in the docker-compose from lemmy also listens to port 80 and you just need to add

server {
    listen 80;
    server_name my_domain.tld;

    location / {
        proxy_pass http://localhost:LEMMY_PORT;
        proxy_set_header Host $host;
        include proxy_params;
    }
}

to the nginx.conf of the container.

Then you should have it accessable from port 80 without the host nginx (of course you need to stop the host nginx then).

[-] penguin_ex_machina@lemmy.world 1 points 1 year ago

So looking at this again now, am I taking that whole block and adding it to the container's nginx.conf? If so, does that mean I have to change what port it's currently listening to (because there's already a rule in the file for port 80)?

There's a comment in that server rule that says "this is the port inside docker" and a comment immediately after that says "this is facing the public web", which confuses me.

this post was submitted on 12 Jun 2023
0 points (NaN% liked)

Selfhosted

39700 readers
712 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS