zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
26.09k stars 1.78k forks source link

Websocket connection to wss: <site> failed: There was a bad response from the server. #4742

Closed atlas1Mc closed 2 months ago

atlas1Mc commented 2 months ago

Trilium Version

0.63.5

What operating system are you using?

Other Linux

What is your setup?

Server access only

Operating System Version

Rocky Linux 8.9 (Green Obsidian)

Description

When browsing to site the following is repeated every second in the web console: Websocket connection to wss: failed: There was a bad response from the server.

The site is somewhat working, but somethings are broken.

My setup is: Server: Rocky Linux 8.9 IP 192.168.1.77 Reverse Proxy: Apache/2.4.37 (rocky) Trilium Version: 0.63.5 Container engine: Podman TLS enabled with Lets Encrypt certs. Subdomain: trilium..com is resolvable.

Quadlet Config:

[Unit]
Description=Trilium Notes Server
After=local-fs.target network.target

[Container]
Image=zadam/trilium:0.63.5
IP=10.88.0.20
PodmanArgs=--privileged --tty
PublishPort=127.0.0.1:8080:8080
Volume=/opt/trilium/trilium-data:/home/node/trilium-data

[Service]
Restart=always

[Install]
WantedBy=default.target

Apache configuration file:

<VirtualHost *:80>
    ServerName http://trilium.<domain>.com
    RewriteEngine on
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
<VirtualHost *:443>
    ServerName https://trilium.<domain>.com
    ErrorLog logs/trilium.<domain>.com-error_log
    CustomLog logs/trilium.<domain>.com-access_log common
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule /(.*) ws://127.0.0.1:8080/$1 [P,L]
    AllowEncodedSlashes NoDecode
    SSLProxyEngine on
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    ProxyPass / https://127.0.0.1:8080/ nocanon
    ProxyPassReverse / https://127.0.0.1:8080/
    SSLCertificateFile /etc/letsencrypt/live/trilium.<domain>.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/trilium.<domain>.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Trillium Config:

# Instance name can be used to distinguish between different instances using backend api.getInstanceName()                                                           
instanceName=

# set to true to allow using Trilium without authentication (makes sense for server build only, desktop build doesn't need password)                                 
noAuthentication=false

# set to true to disable backups (e.g. because of limited space on server)
noBackup=false

# Disable automatically generating desktop icon
# noDesktopIcon=true

[Network]
# host setting is relevant only for web deployments - set the host on which the server will listen                                                                   
# host=0.0.0.0
# port setting is relevant only for web deployments, desktop builds run on a fixed port (changeable with TRILIUM_PORT environment variable)                          
port=8080
# true for TLS/SSL/HTTPS (secure), false for HTTP (insecure).
https=true
# path to certificate (run "bash bin/generate-cert.sh" to generate self-signed certificate). Relevant only if https=true                                             
certPath=/home/node/trilium-data/tls/cert.pem
keyPath=/home/node/trilium-data/tls/privkey.pem
# setting to give trust to reverse proxies, a comma-separated list of trusted rev. proxy IPs can be specified (CIDR notation is permitted),                          
# alternatively 'true' will make use of the leftmost IP in X-Forwarded-For, ultimately an integer can be used to tell about the number of hops between               
# Trilium (which is hop 0) and the first trusted rev. proxy.
# once set, expressjs will use the X-Forwarded-For header set by the rev. proxy to determinate the real IPs of clients.                                              
# expressjs shortcuts are supported: loopback(127.0.0.1/8, ::1/128), linklocal(169.254.0.0/16, fe80::/10), uniquelocal(10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7)
trustedReverseProxy=192.168.1.77

Error logs

No response

atlas1Mc commented 2 months ago

Well I figured it out after submitting the bug report, figures.

Anyway, if anyone was curious the example Apache config provided here https://github.com/zadam/trilium/wiki/Apache-proxy-setup was not working for me. It turns out the WebSocket should be addressed as:

RewriteRule /(.*) wss://127.0.0.1:8080/$1 [P,L]

worked, but this one did not:

RewriteRule /(.*) ws://127.0.0.1:8080/$1 [P,L]

One simple "s", lol.