WebSocket connection Zammad

Infos:

  • Used Zammad version: 6.1.0-1698142833.c4a2d029.focal
  • Used Zammad installation type: Install from package
  • Operating system: Ubuntu 20.04.6 LTS
  • Browser + version: Microsoft Edge Version 118.0.2088.76 (Official compilation) (64 bits)

Expected behavior:

  • Access the mobile without giving “server connection lost error”

Actual behavior:

  • It is generating a lost connection to server error when I use the mobile version. It works, but it keeps generating this red error bar.

Steps to reproduce the behavior:

  • Just access the mobile version of Zammad.

I created zammad with ngnix on a machine without an SSL certificate. And I have another machine with an SSL and Apache certificate, I use it to do the reverse proxy. I don’t know how to solve the problem, I’ve tried everything but I can’t find the basis.

When I access the machine that has zammad in the mobile version, the error does not occur. Only when I access the reverse proxy address, but I don’t know how to resolve it.

Zammad.conf (nginx - Machine 1)

#
# this is the nginx config for zammad
#

upstream zammad-railsserver {
    server 127.0.0.1:3000;
}

upstream zammad-websocket {
    server 127.0.0.1:6042;
}

server {
    listen 81;
    listen [::]:81;

    # replace 'localhost' with your fqdn if you want to use zammad from remote
    server_name localhost;

    # security - prevent information disclosure about server version
    server_tokens off;

    root /opt/zammad/public;

    access_log /var/log/nginx/zammad.access.log;
    error_log  /var/log/nginx/zammad.error.log;

    client_max_body_size 50M;

    location ~ ^/(assets/|robots.txt|humans.txt|favicon.ico|apple-touch-icon.png) {
        expires max;
    }

    # legacy web socket server
    location /ws {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header CLIENT_IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 86400;
        proxy_pass http://zammad-websocket;
    }

    # action cable
    location /cable {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header CLIENT_IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 86400;
        proxy_pass http://zammad-railsserver;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header CLIENT_IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Change this line in an SSO setup
        proxy_set_header X-Forwarded-User "";

        proxy_read_timeout 300;
        proxy_pass http://zammad-railsserver;

        gzip on;
        gzip_types text/plain text/xml text/css image/svg+xml application/javascript application/x-javascript application/json application/xml;
        gzip_proxied any;
    }
}

Apache2 (Machine 2)

<VirtualHost *:443>
    ServerName sacmanutencao.lagoasanta.mg.gov.br

    SSLEngine on
    SSLCertificateFile /etc/ssl/private/2024/star_lagoasanta_mg_gov_br.crt
    SSLCertificateKeyFile /etc/ssl/private/2024/private.key
    SSLCACertificateFile /etc/ssl/private/2024/DigiCertCA.crt

    ProxyRequests Off
    ProxyPreserveHost On

    <Location />

        ProxyPass wss://10.1.7.81:81/
        ProxyPassReverse wss://10.1.7.81:81/
		
    	ProxyPass http://10.1.7.81:81/
    	ProxyPassReverse http://10.1.7.81:81/

    	SetOutputFilter proxy-html

    	ProxyHTMLURLMap http://sacmanutencao.lagoasanta.mg.gov.br/ https://sacmanutencao.lagoasanta.mg.gov.br/
    	ProxyHTMLURLMap / https://sacmanutencao.lagoasanta.mg.gov.br/
    	ProxyHTMLURLMap wss://sacmanutencao.lagoasanta.mg.gov.br/ wss://sacmanutencao.lagoasanta.mg.gov.br/

    	RequestHeader unset Accept-Encoding
    	Order allow,deny
    	Allow from all

</Location>


        ErrorLog        ${APACHE_LOG_DIR}/sacmanutencao_error.log
        CustomLog       ${APACHE_LOG_DIR}/sacmanutencao_access.log combined

        # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
#        LogLevel debug
</VirtualHost>

Zammad.access.log

10.1.2.240 - - [06/Nov/2023:14:21:54 +0000] "POST /api/v1/message_receive HTTP/1.1" 200 16 "https://sacmanutencao.lagoasanta.mg.gov.br/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.76"
10.1.2.240 - - [06/Nov/2023:14:22:05 +0000] "POST /graphql HTTP/1.1" 200 1091 "https://sacmanutencao.lagoasanta.mg.gov.br/mobile/" "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Mobile Safari/537.36 Edg/118.0.2088.76"
10.1.2.240 - - [06/Nov/2023:14:22:19 +0000] "POST /api/v1/message_receive HTTP/1.1" 200 16 "https://sacmanutencao.lagoasanta.mg.gov.br/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.76"
10.1.2.240 - - [06/Nov/2023:14:22:39 +0000] "GET /cable HTTP/1.1" 404 14 "-" "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Mobile Safari/537.36 Edg/118.0.2088.76"
10.1.2.240 - - [06/Nov/2023:14:22:44 +0000] "POST /api/v1/message_receive HTTP/1.1" 200 16 "https://sacmanutencao.lagoasanta.mg.gov.br/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.76"

Zammad.error.log

2023/11/06 11:53:01 [error] 462594#462594: *995 connect() failed (111: Connection refused) while connecting to upstream, client: 10.1.2.240, server: localhost, request: "GET /api/v1/available?_=1699270096417 HTTP/1.1", upstream: "http://127.0.0.1:3000/api/v1/available?_=1699270096417", host: "sacmanutencao.lagoasanta.mg.gov.br", referrer: "https://sacmanutencao.lagoasanta.mg.gov.br/"
2023/11/06 11:53:01 [error] 462594#462594: *464 connect() failed (111: Connection refused) while connecting to upstream, client: 10.1.2.240, server: localhost, request: "POST /api/v1/message_receive HTTP/1.1", upstream: "http://127.0.0.1:3000/api/v1/message_receive", host: "sacmanutencao.lagoasanta.mg.gov.br", referrer: "https://sacmanutencao.lagoasanta.mg.gov.br/"
2023/11/06 11:53:01 [error] 462594#462594: *464 connect() failed (111: Connection refused) while connecting to upstream, client: 10.1.2.240, server: localhost, request: "POST /api/v1/message_send HTTP/1.1", upstream: "http://127.0.0.1:3000/api/v1/message_send", host: "sacmanutencao.lagoasanta.mg.gov.br", referrer: "https://sacmanutencao.lagoasanta.mg.gov.br/"
2023/11/06 11:53:01 [error] 462594#462594: *1024 connect() failed (111: Connection refused) while connecting to upstream, client: 10.1.2.240, server: localhost, request: "GET /cable HTTP/1.1", upstream: "http://127.0.0.1:3000/cable", host: "sacmanutencao.lagoasanta.mg.gov.br"
2023/11/06 11:53:03 [error] 462594#462594: *464 connect() failed (111: Connection refused) while connecting to upstream, client: 10.1.2.240, server: localhost, request: "GET /api/v1/available?_=1699270096418 HTTP/1.1", upstream: "http://127.0.0.1:3000/api/v1/available?_=1699270096418", host: "sacmanutencao.lagoasanta.mg.gov.br", referrer: "https://sacmanutencao.lagoasanta.mg.gov.br/"
2023/11/06 11:53:05 [error] 462594#462594: *464 connect() failed (111: Connection refused) while connecting to upstream, client: 10.1.2.240, server: localhost, request: "GET /api/v1/available?_=1699270096419 HTTP/1.1", upstream: "http://127.0.0.1:3000/api/v1/available?_=1699270096419", host: "sacmanutencao.lagoasanta.mg.gov.br", referrer: "https://sacmanutencao.lagoasanta.mg.gov.br/"
2023/11/06 11:53:05 [error] 462594#462594: *1028 connect() failed (111: Connection refused) while connecting to upstream, client: 10.1.2.240, server: localhost, request: "POST /graphql HTTP/1.1", upstream: "http://127.0.0.1:3000/graphql", host: "sacmanutencao.lagoasanta.mg.gov.br", referrer: "https://sacmanutencao.lagoasanta.mg.gov.br/mobile/error?redirect=1"
2023/11/06 11:53:08 [error] 462594#462594: *1036 upstream prematurely closed connection while reading response header from upstream, client: 10.1.2.240, server: localhost, request: "GET /ws HTTP/1.1", upstream: "http://127.0.0.1:6042/ws", host: "sacmanutencao.lagoasanta.mg.gov.br"
2023/11/06 13:04:53 [error] 462594#462594: *2125 upstream prematurely closed connection while reading response header from upstream, client: 10.1.2.240, server: localhost, request: "GET /ws HTTP/1.1", upstream: "http://127.0.0.1:6042/ws", host: "sacmanutencao.lagoasanta.mg.gov.br"

Mobile version error:

WebSocket connection to 'wss://sacmanutencao.lagoasanta.mg.gov.br/cable' failed: action_cable.js:197

Hi @brnxx. What is logged in the production.log of Zammad itself?

1 Like

Hello!

I will take a look.

@brnxx please remove the uploaded file, it’s not needed to upload the whole file. Just have a look into your log when you open Zammad. Something like STARTED GET "/cable" ... should be there. This is the interesting part.

1 Like

Sorry. I fixed.

Yes, I found that part. I believe that’s it.

I, [2023-11-07T12:34:26.554128#464305-65400]  INFO -- : Started GET "/cable" for 10.1.2.240 at 2023-11-07 12:34:26 +0000
I, [2023-11-07T12:34:26.556903#464305-65400]  INFO -- : Started GET "/cable/"[non-WebSocket] for 10.1.21.80 at 2023-11-07 12:34:26 +0000
E, [2023-11-07T12:34:26.556936#464305-65400] ERROR -- : Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: )
I, [2023-11-07T12:34:26.556956#464305-65400]  INFO -- : Finished "/cable/"[non-WebSocket] for 10.1.21.80 at 2023-11-07 12:34:26 +0000

There is an issue with your proxies. The line Started GET "/cable/"[non-WebSocket] should start with Started GET "/cable/"[WebSocket].

This topic was automatically closed 360 days after the last reply. New replies are no longer allowed.