• [deleted]

  • Edited

mekici Can you share your proxy settings ? Mine as as below

In the top of the site nginx.conf file

map $http_upgrade $type {
  default "web";
  websocket "ws";
}

Then in the server block

	location @ws {
	    proxy_pass             http://127.0.0.1:2083;
	    proxy_read_timeout     60;
	    proxy_connect_timeout  60;
	    proxy_redirect         off;

	    # Allow the use of websockets
	    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;
	}

Then finally, in the Flarum issued .nginx.conf file, changed

location / {
  try_files $uri $uri/ /index.php?$query_string;
}

To

location @web {
  try_files $uri $uri/ /index.php?$query_string;
}

Restarted NGINX. All that does it leave me with a site where rewrite no longer works, and the websocket doesn't work either. I just end up with this

Obviously, the ports are wrong here, so I changed settings.php as below

        $defaults = [
            'server-host' => '0.0.0.0',
            'server-port' => 2083,
            'js-client-host' => $host,
            'js-client-port' => 2083,
            'js-client-secure' => $secure,
            'php-client-host' => $host,
            'php-client-port' => 2083,
            'php-client-secure' => $secure,
            'max-connections' => 1000,
            'app-key' => md5($host),
            'app-secret' => md5($this->config->offsetGet('database.password')),
        ];

Still doesn't work 🙁

    [deleted] I did the same configuration. The only difference is that I used port 6001.

    I did not do anything in settings.php.

      • [deleted]

      mekici Yep. Doesn't work.

      I'll post the config I used on discuss as soon as I'm behind a PC. My apologies for this rough start.

        map $http_upgrade $type {
          default "web";
          websocket "ws";
        }

        Similar to what you have, added above the server block for the domain in nginx.

        Then in the server block for the domain:

        	location @ws {
        	    proxy_pass             http://127.0.0.1:8443;
        	    proxy_set_header Host  $host;
        	    proxy_read_timeout     60;
        	    proxy_connect_timeout  60;
        	    proxy_redirect         off;
        
        	    # Allow the use of websockets
        	    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;
        	}

        In the config.php we use:

        <?php return array (
          // all other stuff
          'websocket' => [
              'server-port' => 8443,
              'js-client-port' => 443,
              'php-client-host' => '127.0.0.1',
              'php-client-port' => 8443,
              'php-client-secure' => false,
          ]
        );

        This is where you override the Settings.php defaults @[deleted] 😉

        The daemon is running using php flarum realtime:serve no other options provided. Make sure that the port you choose is open, the default one is 6001. But we are using 8443 because CloudFlare blocks 6001 I think.

          • [deleted]

          luceos This is where you override the Settings.php defaults @phenomlab

          Yes, I know. I only hacked the settings.php file for testing

            luceos I am using port 2083 and this port is open.

            When I run php flarum realtime:serve everything is as it should be.

            My server.conf:

            map $http_upgrade $type {
              default "web";
              websocket "ws";
            }
            
            server {
                listen 443 ssl http2;
                listen [::]:443 ssl http2;
            	ssl_certificate /etc/ssl/cert.pem;
                ssl_certificate_key /etc/ssl/key.pem;
            	ssl_client_certificate /etc/ssl/cloudflare.crt;
                ssl_verify_client on;
            	server_name flarumtr.com;
            	index index.php index.html index.htm;
            	root /var/www/flarumtr/public;
            	client_max_body_size 40M;
            	
            	location ~ \.php$ {
                      fastcgi_split_path_info ^(.+\.php)(/.+)$;
                      #fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            	  fastcgi_pass 127.0.0.1:9000;
                      fastcgi_index index.php;
                      include fastcgi_params;
                      fastcgi_param SCRIPT_FILENAME 
                      $document_root$fastcgi_script_name;
                      fastcgi_intercept_errors off;
                      fastcgi_buffer_size 16k;
                      fastcgi_buffers 4 16k;
                      fastcgi_connect_timeout 90s;
                      fastcgi_send_timeout 90s;
                      fastcgi_read_timeout 90s;
                }
            	
            	location @ws {
            	    proxy_pass             http://127.0.0.1:2083;
            	    proxy_set_header Host  $host;
            	    proxy_read_timeout     60;
            	    proxy_connect_timeout  60;
            	    proxy_redirect         off;
            
            	    # Allow the use of websockets
            	    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;
            	}
            .....

            my config.php

            <?php return array (
              'debug' => false,
              'database' => 
              array (
                'driver' => 'mysql',
                'host' => 'localhost',
                'port' => 3306,
                'database' => 'xxxxx',
                'username' => 'xxxxx',
                'password' => 'xxxx',
                'charset' => 'utf8mb4',
                'collation' => 'utf8mb4_unicode_ci',
                'prefix' => '',
                'strict' => false,
                'engine' => 'InnoDB',
                'prefix_indexes' => true,
              ),
              'url' => 'https://flarumtr.com',
              'paths' => 
              array (
                'api' => 'api',
                'admin' => 'admin',
              ),
              'headers' => 
              array (
                'poweredByHeader' => true,
                'referrerPolicy' => 'same-origin',
              ),
              'websocket' => [
                  'server-port' => 2083,
                  'js-client-port' => 443,
                  'php-client-host' => '127.0.0.1',
                  'php-client-port' => 2083,
                  'php-client-secure' => false,
              ]
            );

            Is there somewhere I'm doing wrong? Unfortunately I couldn't get it to work. error message in browser

              mekici 'websocket' => [
              'server-port' => 2083,
              'js-client-port' => 443,
              'php-client-host' => '127.0.0.1',
              'php-client-port' => 2083,
              'php-client-secure' => false,
              ]

              This all looks fine, have you restarted nginx? Other than that:

              • are you using cloudflare?
              • pusher provides more debugging information when debug is enabled in your config.php for this extension

                luceos of course I restarted nginx. Yes, I'm using Cloudflare. Updated Kyrne Websocket plugin (v 2.8.4). I tried it it worked.

                • [deleted]

                mekici No, I haven't tried. Was going to try tomorrow now

                • [deleted]

                mekici can you contact me on discord - phenomlab#4801

                  Just to add, if someone's using systemd, you can use:
                  /etc/systemd/system/flarum-realtime.service:

                  [Unit]
                  Description=flarum-realtime
                  StartLimitIntervalSec=0
                  
                  [Service]
                  Type=simple
                  User=flarum-user
                  WorkingDirectory=/var/www/flarum
                  ExecStart=/usr/bin/php7.4 flarum realtime:serve
                  Restart=always
                  RestartSec=5
                  
                  [Install]
                  WantedBy=multi-user.target

                  I decided to remove our plans for now, people who paid for a subscription have received or can request a refund.

                  We will keep working on this extension for our own customers and for sponsored communities. In the meantime we will look at setting up some documentation and use cases.

                  Several issues found with the extension while going over errors from our hosted communities:

                  • Queue jobs would hit the timeout because the default timeout is 60s, which has now been increased. Sending took a long time because it loops over all recipients then dispatches the websocket event synchronously, with the:
                  • upgrade of the pusher php library events are now dispatched asynchronously
                  • events send to guest users would never arrived, realtime switched from channel public to guests a while ago
                  • duplicate events would be sent for events for non public discussions and the likes
                    3 months later

                    A while ago I removed all plans from this extension as configuring it seems to be very problematic. Now that our Blomstra hosting platform has been released, I want to move forward in making this extension stable. For this I need a couple of patient people willing to install, configure and run the extension. We'll do this so that we can improve the documentation and ready the extension up for wider use.

                    If you have an interest in helping out, please contact me on discord, I will grant you a free lifetime license of this extension in return for active bug reporting, testing and patience.

                    Edit: I have sufficient testers, thanks for your interest everyone. Will ship a new version soon.

                    15 days later

                    Will it be possible to configure this under a path (e.g. /scoket) on hosts that do not allow open ports and the only ports available are 80 and 443?