Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use WSS with SSL and HTTPS ? #1041

Open
nathabon opened this issue Nov 13, 2023 · 1 comment
Open

How to use WSS with SSL and HTTPS ? #1041

nathabon opened this issue Nov 13, 2023 · 1 comment

Comments

@nathabon
Copy link

I have made a website using PHP with Apache, and using Ratchet to work with Weksockets that I host on my Raspberry Pi, which is running Raspbian GNU/Linux 11 (bullseye). Once I have set up and SSL certification with Cerbot, I tried, and see that I have to use WSS instead of WS. I have those files : app.js :

var hostname = window.location.hostname;
var port = 8001;
var ws = new WebSocket('ws://' + hostname + ':' + port + "?id_class=" + id + "&id_user=" + id_user + "&chap_name=" + chap_name + "");

and the server.php file :

<?php

require __DIR__ . '/../vendor/autoload.php';

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

require "EditorServer.php";
require __DIR__ . "/../vendor/autoload.php";

$port = isset($_SERVER["CHAT_SERVER_PORT"]) ? $_SERVER["CHAT_SERVER_PORT"] : 8001;
$bindAddr = isset($_SERVER['CHAT_BIND_ADDR']) ? $_SERVER['CHAT_BIND_ADDR'] : '0.0.0.0';


$file = "lecon.txt";

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new MyApp\EditorServer($file)
        )
    ),
    $port, $bindAddr
);

printf("Websocket Editor server running on %s:%s.\n--\n", $bindAddr, $port);
$server->run();

So I tried to put "wss" instead of "ws" in the app.Js file, but is said in the Google Chrome console that "app.js:14 WebSocket connection to 'wss://MYSITE:8001/?id_class=1&id_user=6&chap_name=' failed:". I check many tutorials, but each time it didn't work. So do you know ho to make it work ?

@vb-dot
Copy link

vb-dot commented Jan 29, 2024

If you are running on Apache or NGINX, you will also need to use a reverse webbproxy and redirect the traffic.
Make sure your webserver can resolve you domain towards its own ip, otherwise you will get binding problems.
Also make sure that you have the right ports open in your firewall and on server firewall e.g. iptables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants