toeverything / AFFiNE

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
https://affine.pro
Other
39.96k stars 2.57k forks source link

Issue with Self-Hosting AFFiNE and Nginx #5993

Closed NeoHuncho closed 6 months ago

NeoHuncho commented 6 months ago

What happened?

I’ve successfully self-hosted AFFiNE using the compose file found in the .github directory. Everything works perfectly when I’m on my local network, and I appreciate the amazing work!

However, I encounter an issue when I use Nginx to allow external access to my self-hosted AFFiNE through the internet. Specifically, it remains in a constant loop of syncing for the workspaces that I created and synced on my local network, as well as for new ones that I make.

Could someone please help me figure out why this is happening? Thank you!

Distribution version

macOS x64 (Intel)

What browsers are you seeing the problem on if you're using web version?

Chrome

Relevant log output

In my chrome console I have multiple of the same error:

WebSocket connection to wss://mysubdomain.mydomain.com/socket.io/?EIO=4&transport=websocket failed

The only log that is popping is from the affine_selfhosted service (every ~30 seconds)

EBUG [NextAuth] adapter_getSessionAndUser: {"args":[....]}

Anything else?

No response

Are you willing to submit a PR?

gamersekofy commented 6 months ago

Experiencing the same issue here. Behavior is persistent across Firefox Nightly 125.0a1 (2024-03-02) and Microsoft Edge 123.0.2420.10 on Windows 11, and Samsung Internet v23.0.1.1 on a Tab S7+ running One UI 5.1. Affine looks gorgeous and I would love to use it as an Obsidian replacement!

darkskygit commented 6 months ago

AFFiNE uses the websocket protocol to sync data with the cloud. Please refer to nginx's official blog or other articles to configure websocket support for your nginx: https://www.nginx.com/blog/websocket-nginx/

NeoHuncho commented 6 months ago

Okay, thanks for the answer, I will have a look :)

darkskygit commented 6 months ago

If you're just starting to configure your server, you might also consider caddy, which has https and websocket support out of the box: https://caddyserver.com/docs/

If you just want to access the services on your server from anywhere, you can also consider tailscale or zerotier, which allow you to connect directly to your server in an encrypted manner through a fixed IP or private domain name at any network, and do not require purchasing a domain name and configuration https

NeoHuncho commented 6 months ago

For anybody using nginx proxy manager and having the same issue:

you just need to edit your proxy host and enable websockets on the details tab (see image) Screenshot 2024-03-04 at 14 20 06

NeoHuncho commented 6 months ago

Thanks for the answer and suggestion @darkskygit ! Maybe it could be interesting to add a footnote on web sockets on the self-hosting guide. I can open a PR if needed :)

darkskygit commented 6 months ago

Thanks for the answer and suggestion @darkskygit ! Maybe it could be interesting to add a footnote on web sockets on the self-hosting guide. I can open a PR if needed :)

the document in repo is outdated, now we have a internal affine workspace that is rewriting related documents once we complete the relevant work, we will publish it on our social accounts

gamersekofy commented 6 months ago

Thanks everyone, enabling websocket support worked! For anyone in the future, here's what the block for affine looks like in my nginx conf file:

server {
    server_name affine.your.domain; 

    location / {
        proxy_pass http://localhost:3010; 
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

  <auto-generated certbot SSL stuff here>
}
affine-issue-bot[bot] commented 6 months ago

Issue Status: ✅ Answered

✅ Answered

The issue actually turned out to be a question or a misunderstanding, and it has been answered or resolved.

This is an automatic reply by the bot.

Tatametheus commented 5 months ago

@gamersekofy Hi, I'm using nginx proxy manager too and I have the same configs as yours. But, I got cors error. Did you see it before? image

Access to font at 'https://cdn.affine.pro/fonts/Inter-Light-BETA.woff' from origin 'http:/xxxxxxx:3010' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.