From 2b6e5e663f8326ca9cb1f5dbd109fa82bfd49673 Mon Sep 17 00:00:00 2001 From: crocodile2024 <171804404+crocodile2024@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:54:30 +0200 Subject: [PATCH 1/6] Add new Tutorial for an soketi-Server --- .../01.de.md | 215 ++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md diff --git a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md new file mode 100644 index 000000000..6e7d1075e --- /dev/null +++ b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md @@ -0,0 +1,215 @@ +--- +SPDX-License-Identifier: MIT +path: "/tutorials/setup-soketi-websocket-server-behind-reverse-proxy" +slug: "setup-soketi-websocket-server-behind-reverse-proxy" +date: "2024-08-04" +title: "Installation eines Soketi WebSocket-Servers hinter einem Reverse-Proxy-Server (NGINX)" +short_description: "In diesem Tutorial erfahren Sie, wie Sie einen Soketi WebSocket-Server hinter einem Reverse-Proxy-Server, auf der Basis eines NGINX-Servers, einrichten und betreiben." +tags: ["WebSockets", "NGINX"] +author: "crocodile2024" +author_link: "https://github.com/crocodile2024" +author_img: "" +author_description: "" +language: "de" +available_languages: ["de"] +header_img: "header-1" +--- + +## Einleitung + +In diesem Tutorial lernen Sie, wie Sie einen Soketi WebSocket-Server hinter einem NGINX Reverse-Proxy-Server betreiben können. Dieser ist dann durch den NGINX Reverse-Proxy-Server mit einer SSL-Verschlüsselung geschützt. Das SSL-Zertifikat wird mit Let's Encrypt erstellt und ist somit kostenlos. Die Erneuerung dieses Zertifikats erfolgt automatisch mit der Hilfe von dem Komandozeilenprogramm acme.sh. + +Offizielle Dokumentation: [https://docs.soketi.app/](https://docs.soketi.app/)
+Projekt Website: [https://soketi.app/](https://soketi.app/) + +**Vorraussetzungen** + +* Sie benötihen einen Domain-Namen (Sub-Domain ist ausreichend) +* Entwas Erfahrung im Umgang mit NodeJS und NPM +* einen Server (zum Beispiel in der [Hetzner Cloud](https://hetzner.cloud)) + +## Schritt 1 - Neuer Cloud-Server bestellen + +* Melden Sie sich in der [Hetzner Cloud Konsole](https://console.hetzner.cloud) an. +* Erstellen Sie, wenn Sie das wollen, ein neues Peojekt und nennen Sie es, wie Sie möchten. +* Wählen Sie einen Standort und ein Server-Modell. +* Klicken Sie auf "Server hinzufügen". In diesem Tutorial benutze ich das Betriebsystem Debian 12. +* Als Cloud-Konfig müssen Sie nichts eingeben. +* Wählen Sie Ihren SSH-Schlüssel + * Sie können [diesen Artikel](https://help.github.com/en/enterprise/2.16/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) lesen, falls Sie Hilfe bei der Erstellung eines SSH-Schlüssels benötigen. +* Trahen Sie den Namen Ihres Servers noch im Feld `name` ein (ws.example.de) +* Klicken Sie auf `Kostenpflichtig bestellen` + + +## Schritt 2 - DNS einrichten + +Sie benötigen für dieses Tutorial einen DNS-Eintrag, welcher auf Ihren in Schritt 1 bestellen Server verweist. Dies ist notwendig, damit Ihnen ein SSL-Zertifikat ausgestellt werden kann. + +Ihre DNS-Konfiguration sollte dann so ausehen: + +``` +# Name Type Value +ws IN A 10.0.0.1 +ws IN AAAA 2001:db8:1234::1 +``` + +## Step 3 - Updates installieren und notwendige Pakete installieren + +Warten Sie einen kurzen Moment, bis Ihr bestellter Server installier wurde. Sobald dies abgeschlossen ist, können Sie sich mit dem Server über SSH und Ihrer IP-Adresse oder der in Schritt 2 festgelegten Subdomain (hier ws.example.de) verbinden. + +Paketlisten aktualisieren und Updates installieren: +`apt update && apt upgrade -y` + +Anschließend sollten Sie den Server neustarten, um eventuell den aktualisierten Kernel zu laden. + +Als nächstes installieren wir alle notwendigen Pakete: + +'apt-get install git python3 gcc build-essential nodejs npm' + +Wenn Sie einen Server in der Hetzner-Cloud verwenden, dann müssen Sie noch das Pekt 'apparmor' installieren. Ansonsten würden Sie im späteren Verlauf dieses Tutorials Probleme bekommen. + +'apt-get install apparmor' + +Anschließend installieren wir die beiden NodeJS-Pakete soketi und pm2: + +'npm install -g @soketi/soketi' +'npm install -g pm2' + +## Schritt 4 - Konfiguration für Soketi erstellen + +Sie können die folgende Konfigurationsdatek als Basis benutzen und gegebenenfalls auf Ihre Bedürfnisse anpassen: + +'{ + "host": "127.0.0.1", + "port": 6001, + "appManager": { + "driver": "array", + "options": { + "apps": [ + { + "id": "my-app-id", + "key": "my-app-key", + "secret": "my-app-secret", + "name": "My App", + "enableClientMessages": true, + "enableStatistics": true + } + ] + } + } +}' + +Wenn diese Konfigurationsdatei berwendet wird, dann muss keine weitere Konfiguration vor dem ersten Start gemacht werden. + +Kopieren Sie sich die Konfiguration, welche Sie für Ihren Zweck benötigen. Erstellen sie dann mit einem Texteditor in dem DSH-Terminal eine neue Datei: + +'nano config.json' + +Fügen Sie dann den kopierten Inhalt in die Datei ein und speichern Sie die Datei mit der Tastenkompination 'STRG + O'. + +## Schritt 5 - Erster Start des Soketi-Servers (noch ohne PM2): +Starten Sie nun den Soketi-Server, indem Sie den folgenden Befehl in einem Terminal ausführen: + +'soketi start --config=""' + + +## Schritt 6 - Erster Test des Websocket-Servers mit Laravel 11: + +Ändern Sie die folgenden Werte in der .env-Datei: + +'BROADCAST_DRIVER=pusher +PUSHER_APP_ID=your-app-id +PUSHER_APP_KEY=your-app-key +PUSHER_APP_SECRET=your-app-secret +PUSHER_APP_CLUSTER=mt1' + +Überprüfen Sie die Einstellungen in der folgenden Datei 'config/brodcasting.php': + +'connections' => [ + 'pusher' => [ + 'driver' => 'pusher', + 'key' => env('PUSHER_APP_KEY'), + 'secret' => env('PUSHER_APP_SECRET'), + 'app_id' => env('PUSHER_APP_ID'), + 'options' => [ + 'cluster' => env('PUSHER_APP_CLUSTER'), + 'useTLS' => true, + ], + ], + // weitere Verbindungen... +], + +## Schritt 7 - Erste Events auslösen + +Sie können nun die ersten Events mit Ihrem WebSocket-Server verschicken. + + +## Schritt 8 - Auto-Start für den Socketi Server konfigurieren: + +Damit der Soketi-Server auch nach einem Neustart des Cloud-Servers wieder automatisch gestartet wird, müssen wir nun noch 'pm2' einrichten: + +Führen Sie hierzu die folgenden Befehle aus: + +- pm2 start soketi --name WebSoket-Server -- start --config="" +- pm2 startup (Dann wird der autostart aktiviert) Folgen Sie den Anweisungen auf dem Bildschirm. + + +## Schritt 9 - Reverse Proxy einrichten +Nun muss der Reverse Proxy Server noch eingerichtet werden. Dieser wird die SSL-Verbindung bereitstellen und dann an den soketi Server weitergeben. Erstellen Sie hierfür eine neue Datei im Ordner '/etc/nginx/sites-available/'. + +'mkdir /etc/nginx/ssl' +'nano /etc/nginx/sites-available/soketi' + +Fühen Sie folgenden Inhalt in die Datei ein: + +'server { + listen 443 ssl; + server_name ws.example.de; + + ssl_certificate /etc/nginx/ssl/ws.example.de.cer; + ssl_certificate_key /etc/nginx/ssl/ws.example.de.key; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + + location / { + proxy_pass http://localhost:6001; # Ersetze den Port, falls soketi auf einem anderen Port läuft + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} + +server { + listen 80; + server_name ws.example.de; + + location / { + return 301 https://$host$request_uri; + } +}' + +## Schritt 10 - SSL-Zertifikat erstellen + +Für die Erstellung des Zertifikats benutzen wir das Shell-Script 'acme.sh'. Dieses installieren Sie mit dem folgenden Befehl: + +'curl https://get.acme.sh | sh -s email=' + + An diese E-Mail-Adresse werden dann Erinnerungen geschickt, wenn ein Zertifikat abläuft oder wenn es Probleme bei der Verlängerung gibt. + + 'systemctl stop nginx && acme.sh --issue -d ws.example.de --standalone' + + 'ln -s /etc/nginx/sites-available/ws /etc/nginx/sites-enabled/ws' + + 'acme.sh --install-cert -d ws.example.de --cert-file /etc/nginx/ssl/mustermann-domain.de.cer --key-file /etc/nginx/ssl/ws.example.de.key --fullchain-file /etc/nginx/ssl/fullchain.pem --reloadcmd "systemctl reload nginx"' + + 'systemctl start nginx' + +## Fertig + +Ihr WebSocket Server ist nun mit einer SSL-Verschlüsselung ausgestattet. In der Konfiguration von Laravel muss nun der Port auf '443' geändert werden. + +##### License: MIT From bafa9e25f3af69e43efeb414f13ef7675f24be16 Mon Sep 17 00:00:00 2001 From: crocodile2024 <171804404+crocodile2024@users.noreply.github.com> Date: Mon, 5 Aug 2024 13:51:17 +0200 Subject: [PATCH 2/6] Update 01.de.md --- .../setup-soketi-websocket-server-behind-reverse-proxy/01.de.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md index 6e7d1075e..ba4daf5d3 100644 --- a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md +++ b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md @@ -200,7 +200,7 @@ Für die Erstellung des Zertifikats benutzen wir das Shell-Script 'acme.sh'. Die An diese E-Mail-Adresse werden dann Erinnerungen geschickt, wenn ein Zertifikat abläuft oder wenn es Probleme bei der Verlängerung gibt. - 'systemctl stop nginx && acme.sh --issue -d ws.example.de --standalone' + 'systemctl stop nginx && acme.sh --issue -d ws.example.de --standalone --server letsencrypt' 'ln -s /etc/nginx/sites-available/ws /etc/nginx/sites-enabled/ws' From 4617add90df118b63219f15bc0e5d5136ef85eca Mon Sep 17 00:00:00 2001 From: crocodile2024 <171804404+crocodile2024@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:26:47 +0200 Subject: [PATCH 3/6] Add files via upload --- .../01.en.md | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md diff --git a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md new file mode 100644 index 000000000..9fa17dbb0 --- /dev/null +++ b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md @@ -0,0 +1,220 @@ +--- +SPDX-License-Identifier: MIT +path: "/tutorials/setup-soketi-websocket-server-behind-reverse-proxy" +slug: "setup-soketi-websocket-server-behind-reverse-proxy" +date: "2024-08-04" +title: "Setting up a Soketi WebSocket Server behind a Reverse Proxy (NGINX)" +short_description: "In this tutorial, you will learn how to set up and operate a Soketi WebSocket server behind an NGINX-based reverse proxy server." +tags: ["WebSockets", "NGINX"] +author: "crocodile2024" +author_link: "https://github.com/crocodile2024" +author_img: "" +author_description: "" +language: "en" +available_languages: ["de"] +header_img: "header-1" +--- + +## Introduction + +In this tutorial, you will learn how to operate a Soketi WebSocket server behind an NGINX reverse proxy server, which will be protected by SSL encryption. The SSL certificate will be created using `Let's Encrypt` and is thus free. The renewal of this certificate is automated with the help of the command-line program acme.sh. + +Official Documentation: [https://docs.soketi.app/](https://docs.soketi.app/)
+Project Website: [https://soketi.app/](https://soketi.app/) + +**Requirement** + +* You need a domain name (a subdomain is sufficient) +* Some experience with NodeJS and NPM +* A server (for example, in the [Hetzner Cloud](https://hetzner.cloud)) + +## Step 1 - Order a new cloud server + +* Log in to the [Hetzner Cloud Console](https://console.hetzner.cloud). +* Create a new project if you want, and name it as you wish. +* Choose a location and a server model. +* Click on "Add Server". In this tutorial, I use the Debian 12 operating system. +* No need to enter anything in the cloud config. +* Select your SSH key. + * You can read [this article](https://help.github.com/en/enterprise/2.16/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) if you need help creating an SSH key. +* Enter the name of your server in the `name` field (ws.example.de). +* Click on `Order for a fee`. + +## Step 2 - Set up DNS + +You need a DNS entry that points to the server you ordered in step 1. This is necessary for an SSL certificate to be issued to you. + +Your DNS configuration should look like this: + +``` +# Name Type Value +ws IN A 10.0.0.1 +ws IN AAAA 2001:db8:1234::1 +``` + +## Step 3 - Install updates and necessary packages + +Wait a moment until your ordered server is installed. Once completed, you can connect to the server via SSH using your IP address or the subdomain set in step 2 (here ws.example.de). + +Update package lists and install updates: +`apt update && apt upgrade -y` + +Then restart the server to load any updated kernel. + +Next, install all necessary packages: + +`apt-get install git python3 gcc build-essential nodejs npm` + +If you are using a server in the Hetzner Cloud, you need to install the `apparmor` package. Otherwise, you will encounter issues later in this tutorial. + +`apt-get install apparmor` + +Next, install the two NodeJS packages soketi and pm2: + +`npm install -g @soketi/soketi` +`npm install -g pm2` + +## Step 4 - Create configuration for Soketi + +You can use the following configuration file as a basis and adjust it to your needs: + +``` +{ + "host": "127.0.0.1", + "port": 6001, + "appManager": { + "driver": "array", + "options": { + "apps": [ + { + "id": "my-app-id", + "key": "my-app-key", + "secret": "my-app-secret", + "name": "My App", + "enableClientMessages": true, + "enableStatistics": true + } + ] + } + } +} +``` + +If this configuration file is used, no further configuration is required before the first start. + +Copy the configuration you need. Then create a new file with a text editor in the SSH terminal: + +`nano config.json` + +Paste the copied content into the file and save it with the key combination `CTRL + O`. + +## Step 5 - First start of the Soketi server (without PM2): + +Now start the Soketi server by running the following command in a terminal: + +`soketi start --config=""` + +## Step 6 - First test of the WebSocket server with Laravel 11: + +Change the following values in the .env file: + +``` +BROADCAST_DRIVER=pusher +PUSHER_APP_ID=your-app-id +PUSHER_APP_KEY=your-app-key +PUSHER_APP_SECRET=your-app-secret +PUSHER_APP_CLUSTER=mt1 +``` + +Check the settings in the following file `config/broadcasting.php`: + +``` +'connections' => [ + 'pusher' => [ + 'driver' => 'pusher', + 'key' => env('PUSHER_APP_KEY'), + 'secret' => env('PUSHER_APP_SECRET'), + 'app_id' => env('PUSHER_APP_ID'), + 'options' => [ + 'cluster' => env('PUSHER_APP_CLUSTER'), + 'useTLS' => true, + ], + ], + // other connections... +], +``` + +## Step 7 - Trigger first events + +You can now send the first events with your WebSocket server. + +## Step 8 - Configure auto-start for the Soketi server: + +To ensure the Soketi server starts automatically after a reboot of the cloud server, we need to configure `pm2`: + +Run the following commands: + +- `pm2 start soketi --name WebSocket-Server -- start --config=""` +- `pm2 startup` (Then the autostart is activated) Follow the instructions on the screen. + +## Step 9 - Set up reverse proxy + +Now we need to set up the reverse proxy server. This will provide the SSL connection and then forward it to the soketi server. Create a new file in the `/etc/nginx/sites-available/` directory. + +`mkdir /etc/nginx/ssl` +`nano /etc/nginx/sites-available/soketi` + +Add the following content to the file: + +``` +server { + listen 443 ssl; + server_name ws.example.de; + + ssl_certificate /etc/nginx/ssl/ws.example.de.cer; + ssl_certificate_key /etc/nginx/ssl/ws.example.de.key; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + + location / { + proxy_pass http://localhost:6001; # Replace the port if soketi is running on a different port + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} + +server { + listen 80; + server_name ws.example.de; + + location / { + return 301 https://$host$request_uri; + } +} +``` + +## Step 10 - Create SSL certificate + +To create the certificate, we use the shell script `acme.sh`. Install it with the following command: + +`curl https://get.acme.sh | sh -s email=` + +You will receive reminders at this email address when a certificate expires or if there are issues with renewal. + +``` +systemctl stop nginx && acme.sh --issue -d ws.example.de --standalone --server letsencrypt +ln -s /etc/nginx/sites-available/ws /etc/nginx/sites-enabled/ws +acme.sh --install-cert -d ws.example.de --cert-file /etc/nginx/ssl/ws.example.de.cer --key-file /etc/nginx/ssl/ws.example.de.key --fullchain-file /etc/nginx/ssl/fullchain.pem --reloadcmd "systemctl reload nginx" +systemctl start nginx +``` + +## Done + +Your WebSocket server is now equipped with SSL encryption. In the Laravel configuration, you need to change the port to `443`. + +##### License: MIT From b179e8c2170459f12a8d6dd5dd7c5cdcc10c2e0b Mon Sep 17 00:00:00 2001 From: "svenja.michal" Date: Tue, 13 Aug 2024 14:49:30 +0200 Subject: [PATCH 4/6] Spelling and formatting updates --- .../01.de.md | 327 ++++++++++++------ .../01.en.md | 294 +++++++++++----- 2 files changed, 429 insertions(+), 192 deletions(-) diff --git a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md index ba4daf5d3..b432c7a53 100644 --- a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md +++ b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md @@ -1,85 +1,86 @@ --- SPDX-License-Identifier: MIT -path: "/tutorials/setup-soketi-websocket-server-behind-reverse-proxy" +path: "/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/de" slug: "setup-soketi-websocket-server-behind-reverse-proxy" -date: "2024-08-04" +date: "2024-08-13" title: "Installation eines Soketi WebSocket-Servers hinter einem Reverse-Proxy-Server (NGINX)" -short_description: "In diesem Tutorial erfahren Sie, wie Sie einen Soketi WebSocket-Server hinter einem Reverse-Proxy-Server, auf der Basis eines NGINX-Servers, einrichten und betreiben." +short_description: "Dieses Tutorial erklärt, wie man einen Soketi WebSocket-Server hinter einem Reverse-Proxy-Server, auf der Basis eines NGINX-Servers, einrichtet und betreibt." tags: ["WebSockets", "NGINX"] author: "crocodile2024" author_link: "https://github.com/crocodile2024" -author_img: "" +author_img: "https://avatars.githubusercontent.com/u/171804404" author_description: "" language: "de" -available_languages: ["de"] -header_img: "header-1" +available_languages: ["en", "de"] +header_img: "header-5" +cta: "cloud" --- ## Einleitung -In diesem Tutorial lernen Sie, wie Sie einen Soketi WebSocket-Server hinter einem NGINX Reverse-Proxy-Server betreiben können. Dieser ist dann durch den NGINX Reverse-Proxy-Server mit einer SSL-Verschlüsselung geschützt. Das SSL-Zertifikat wird mit Let's Encrypt erstellt und ist somit kostenlos. Die Erneuerung dieses Zertifikats erfolgt automatisch mit der Hilfe von dem Komandozeilenprogramm acme.sh. +Dieses Tutorial erklärt, wie man einen Soketi WebSocket-Server hinter einem NGINX Reverse-Proxy-Server betreiben kann. Dieser ist dann durch den NGINX Reverse-Proxy-Server mit einer SSL-Verschlüsselung geschützt. Das SSL-Zertifikat wird mit Let's Encrypt erstellt und ist somit kostenlos. Die Erneuerung dieses Zertifikats erfolgt automatisch mit der Hilfe von dem Komandozeilenprogramm acme.sh. Offizielle Dokumentation: [https://docs.soketi.app/](https://docs.soketi.app/)
Projekt Website: [https://soketi.app/](https://soketi.app/) **Vorraussetzungen** -* Sie benötihen einen Domain-Namen (Sub-Domain ist ausreichend) +* Domain-Namen (Sub-Domain ist ausreichend) * Entwas Erfahrung im Umgang mit NodeJS und NPM -* einen Server (zum Beispiel in der [Hetzner Cloud](https://hetzner.cloud)) +* Einen Server (zum Beispiel in der [Hetzner Cloud](https://hetzner.cloud)) + * Debian 12 oder Ubuntu 24.04 als Betriebssystem + * SSH-Key empfohlen (siehe [diesen Artikel](https://community.hetzner.com/tutorials/howto-ssh-key/de)) + * Zugriff auf den root-Benutzer oder einen Benutzer mit sudo-Berechtigungen -## Schritt 1 - Neuer Cloud-Server bestellen +**Beispiel-Benennungen** -* Melden Sie sich in der [Hetzner Cloud Konsole](https://console.hetzner.cloud) an. -* Erstellen Sie, wenn Sie das wollen, ein neues Peojekt und nennen Sie es, wie Sie möchten. -* Wählen Sie einen Standort und ein Server-Modell. -* Klicken Sie auf "Server hinzufügen". In diesem Tutorial benutze ich das Betriebsystem Debian 12. -* Als Cloud-Konfig müssen Sie nichts eingeben. -* Wählen Sie Ihren SSH-Schlüssel - * Sie können [diesen Artikel](https://help.github.com/en/enterprise/2.16/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) lesen, falls Sie Hilfe bei der Erstellung eines SSH-Schlüssels benötigen. -* Trahen Sie den Namen Ihres Servers noch im Feld `name` ein (ws.example.de) -* Klicken Sie auf `Kostenpflichtig bestellen` +* Domain: `ws.example.com` +* IPv4: `203.0.113.1` +* IPv6: `2001:db8:1234::1` +## Schritt 1 - Updates installieren und notwendige Pakete installieren -## Schritt 2 - DNS einrichten - -Sie benötigen für dieses Tutorial einen DNS-Eintrag, welcher auf Ihren in Schritt 1 bestellen Server verweist. Dies ist notwendig, damit Ihnen ein SSL-Zertifikat ausgestellt werden kann. - -Ihre DNS-Konfiguration sollte dann so ausehen: - -``` -# Name Type Value -ws IN A 10.0.0.1 -ws IN AAAA 2001:db8:1234::1 -``` - -## Step 3 - Updates installieren und notwendige Pakete installieren - -Warten Sie einen kurzen Moment, bis Ihr bestellter Server installier wurde. Sobald dies abgeschlossen ist, können Sie sich mit dem Server über SSH und Ihrer IP-Adresse oder der in Schritt 2 festgelegten Subdomain (hier ws.example.de) verbinden. +Verbinde dich über SSH und IP-Adresse mit deinem Server. Paketlisten aktualisieren und Updates installieren: -`apt update && apt upgrade -y` +```bash +sudo apt update && sudo apt upgrade -y +``` -Anschließend sollten Sie den Server neustarten, um eventuell den aktualisierten Kernel zu laden. +Starte anschließend den Server neu, um eventuell den aktualisierten Kernel zu laden. Als nächstes installieren wir alle notwendigen Pakete: -'apt-get install git python3 gcc build-essential nodejs npm' +* Installiere Voraussetzungen + ```bash + sudo apt install git python3 gcc build-essential apparmor nginx + ``` -Wenn Sie einen Server in der Hetzner-Cloud verwenden, dann müssen Sie noch das Pekt 'apparmor' installieren. Ansonsten würden Sie im späteren Verlauf dieses Tutorials Probleme bekommen. +* Installiere nodeJS + ```bash + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash + source ~/.bashrc + nvm install 18 && nvm use 18 + ``` -'apt-get install apparmor' +* Installiere die beiden NodeJS-Pakete `soketi` und `pm2`: + ```bash + npm install -g @soketi/soketi + npm install -g pm2 + ``` -Anschließend installieren wir die beiden NodeJS-Pakete soketi und pm2: +## Schritt 2 - Konfiguration für Soketi erstellen -'npm install -g @soketi/soketi' -'npm install -g pm2' +Erstelle eine neue Konfigurationsdatei: -## Schritt 4 - Konfiguration für Soketi erstellen +```bash +nano ~/config.json +``` -Sie können die folgende Konfigurationsdatek als Basis benutzen und gegebenenfalls auf Ihre Bedürfnisse anpassen: +Füge folgenden Inhalt hinzu und passe es gegebenenfalls an deine Bedürfnisse an: -'{ +```json +{ "host": "127.0.0.1", "port": 6001, "appManager": { @@ -97,77 +98,144 @@ Sie können die folgende Konfigurationsdatek als Basis benutzen und gegebenenfal ] } } -}' +} +``` -Wenn diese Konfigurationsdatei berwendet wird, dann muss keine weitere Konfiguration vor dem ersten Start gemacht werden. +Speichere die Datei mit der Tastenkompination `STRG`+`O`. -Kopieren Sie sich die Konfiguration, welche Sie für Ihren Zweck benötigen. Erstellen sie dann mit einem Texteditor in dem DSH-Terminal eine neue Datei: +Wenn diese Konfigurationsdatei verwendet wird, muss keine weitere Konfiguration vor dem ersten Start gemacht werden. -'nano config.json' +## Schritt 3 - Erster Start des Soketi-Servers (noch ohne PM2) -Fügen Sie dann den kopierten Inhalt in die Datei ein und speichern Sie die Datei mit der Tastenkompination 'STRG + O'. +Starte nun den Soketi-Server mit folgendem Befehl: -## Schritt 5 - Erster Start des Soketi-Servers (noch ohne PM2): -Starten Sie nun den Soketi-Server, indem Sie den folgenden Befehl in einem Terminal ausführen: +```bash +soketi start --config="~/config.json" +``` -'soketi start --config=""' +## Schritt 4 - Erster Test des Websocket-Servers mit Laravel 11 +Laravel sollte bereits installiert sein. -## Schritt 6 - Erster Test des Websocket-Servers mit Laravel 11: +
+Falls Laravel noch nicht installiert ist, klicke hier und installiere es jetzt +
+ +```bash +sudo apt update && sudo apt install php php-{mbstring,xml,bcmath,mysql} mariadb-server +cd ~ && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +php composer-setup.php +echo 'alias composer="php ~/composer.phar"' >> ~/.bashrc && source ~/.bashrc +composer create-project --prefer-dist laravel/laravel ~/example +cd ~/example +``` -Ändern Sie die folgenden Werte in der .env-Datei: +Und richte die Datenbank ein: -'BROADCAST_DRIVER=pusher +```bash +sudo mysql +MariaDB [(none)]> CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'secure-password'; +MariaDB [(none)]> GRANT ALL PRIVILEGES ON laravel.* TO 'laravel'@'localhost'; +MariaDB [(none)]> CREATE DATABASE laravel; +MariaDB [(none)]> exit +``` + +Füge die Datenbank-Informationen in der `~/example/.env`-Datei ein: + +```env +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=laravel +DB_USERNAME=laravel +DB_PASSWORD=secure-password +``` + +Führe nun diesen Befehl aus: + +```bash +cd ~/example && php artisan migrate +``` + +
+ +------- + +Fahre nun mit Laravel und Soketi fort. + +
+ +
+ +Ändere die folgenden Werte in der `.env`-Datei: + +> Gib bei app ID, app key und app secret dieselben Informationen an, die auch in `~/config.json` angegeben wurden. + +```env +BROADCAST_DRIVER=pusher PUSHER_APP_ID=your-app-id PUSHER_APP_KEY=your-app-key PUSHER_APP_SECRET=your-app-secret -PUSHER_APP_CLUSTER=mt1' - -Überprüfen Sie die Einstellungen in der folgenden Datei 'config/brodcasting.php': - -'connections' => [ - 'pusher' => [ - 'driver' => 'pusher', - 'key' => env('PUSHER_APP_KEY'), - 'secret' => env('PUSHER_APP_SECRET'), - 'app_id' => env('PUSHER_APP_ID'), - 'options' => [ - 'cluster' => env('PUSHER_APP_CLUSTER'), - 'useTLS' => true, +PUSHER_APP_CLUSTER=mt1 +``` + +Überprüfe die Einstellungen in der folgenden Datei `config/brodcasting.php`: + +```php + [ + 'pusher' => [ + 'driver' => 'pusher', + 'key' => env('PUSHER_APP_KEY'), + 'secret' => env('PUSHER_APP_SECRET'), + 'app_id' => env('PUSHER_APP_ID'), + 'options' => [ + 'cluster' => env('PUSHER_APP_CLUSTER'), + 'useTLS' => true, + ], ], + // other connections... ], - // weitere Verbindungen... -], +]; +``` -## Schritt 7 - Erste Events auslösen +## Schritt 5 - Erste Events auslösen -Sie können nun die ersten Events mit Ihrem WebSocket-Server verschicken. +Die ersten Events können nun mit dem WebSocket-Server verschickt werden. +## Schritt 6 - Auto-Start für den Socketi Server konfigurieren -## Schritt 8 - Auto-Start für den Socketi Server konfigurieren: +Damit der Soketi-Server auch nach einem Neustart des Cloud Servers wieder automatisch gestartet wird, müssen wir nun noch `pm2` einrichten: -Damit der Soketi-Server auch nach einem Neustart des Cloud-Servers wieder automatisch gestartet wird, müssen wir nun noch 'pm2' einrichten: +Führe hierzu die folgenden Befehle aus: -Führen Sie hierzu die folgenden Befehle aus: +```bash +pm2 start soketi --name WebSocket-Server -- start --config="~/config.json" +pm2 startup # Damit wird der autostart aktiviert. Folgen Sie den Anweisungen auf dem Bildschirm. +``` -- pm2 start soketi --name WebSoket-Server -- start --config="" -- pm2 startup (Dann wird der autostart aktiviert) Folgen Sie den Anweisungen auf dem Bildschirm. +## Schritt 7 - Reverse Proxy einrichten +Nun muss der Reverse Proxy Server noch eingerichtet werden. Dieser wird die SSL-Verbindung bereitstellen und dann an den Soketi Server weitergeben. Erstelle hierfür eine neue Datei im Ordner `/etc/nginx/sites-available/`. -## Schritt 9 - Reverse Proxy einrichten -Nun muss der Reverse Proxy Server noch eingerichtet werden. Dieser wird die SSL-Verbindung bereitstellen und dann an den soketi Server weitergeben. Erstellen Sie hierfür eine neue Datei im Ordner '/etc/nginx/sites-available/'. +```bash +sudo mkdir /etc/nginx/ssl +sudo nano /etc/nginx/sites-available/soketi +``` -'mkdir /etc/nginx/ssl' -'nano /etc/nginx/sites-available/soketi' +Füge folgenden Inhalt in die Datei ein: -Fühen Sie folgenden Inhalt in die Datei ein: +> Ersetze `ws.example.com` mit deiner eigenen Domain. -'server { +```nginx +server { listen 443 ssl; - server_name ws.example.de; + server_name ws.example.com; - ssl_certificate /etc/nginx/ssl/ws.example.de.cer; - ssl_certificate_key /etc/nginx/ssl/ws.example.de.key; + ssl_certificate /etc/nginx/ssl/ws.example.com.cer; + ssl_certificate_key /etc/nginx/ssl/ws.example.com.key; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; @@ -185,31 +253,84 @@ Fühen Sie folgenden Inhalt in die Datei ein: server { listen 80; - server_name ws.example.de; + server_name ws.example.com; location / { return 301 https://$host$request_uri; } -}' +} +``` + +
+ +
+Hier klicken, für eine Konfiguration ohne SSL +
+ +*Replace `203.0.113.1` with your own IP address.* + +```nginx +server { + listen 80; + server_name 203.0.113.1; + + location / { + proxy_pass http://localhost:6001; # Replace the port if Soketi is running on a different port + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} +``` -## Schritt 10 - SSL-Zertifikat erstellen +
+
-Für die Erstellung des Zertifikats benutzen wir das Shell-Script 'acme.sh'. Dieses installieren Sie mit dem folgenden Befehl: +
-'curl https://get.acme.sh | sh -s email=' - - An diese E-Mail-Adresse werden dann Erinnerungen geschickt, wenn ein Zertifikat abläuft oder wenn es Probleme bei der Verlängerung gibt. +```bash +sudo ln -s /etc/nginx/sites-available/soketi /etc/nginx/sites-enabled/soketi +sudo rm /etc/nginx/sites-available/default && sudo rm /etc/nginx/sites-enabled/default +sudo nginx -t +sudo systemctl restart nginx +``` - 'systemctl stop nginx && acme.sh --issue -d ws.example.de --standalone --server letsencrypt' - - 'ln -s /etc/nginx/sites-available/ws /etc/nginx/sites-enabled/ws' - - 'acme.sh --install-cert -d ws.example.de --cert-file /etc/nginx/ssl/mustermann-domain.de.cer --key-file /etc/nginx/ssl/ws.example.de.key --fullchain-file /etc/nginx/ssl/fullchain.pem --reloadcmd "systemctl reload nginx"' - - 'systemctl start nginx' +## Schritt 8 - SSL-Zertifikat erstellen + +Bevor du das SSL-Zertifikat erstellst, erstelle passende DNS-Einträge, mit denen die IP-Adressen des Servers auf deine Domain zeigen. + +Die DNS-Konfiguration sollte dann so ausehen: + +```shellsession +# Name Type Value +ws.example.com IN A 203.0.113.1 +ws.example.com IN AAAA 2001:db8:1234::1 +``` + +Wenn mit `dig ws.example.com` die korrekte IP-Adresse angezeigt wird, kannst du das Zertifikat erstellen. + +Für die Erstellung des Zertifikats benutzen wir das Shell-Script `acme.sh`. Dieses kann mit dem folgenden Befehl installiert werden: + +```bash +curl https://get.acme.sh | sh -s email= +``` -## Fertig +An diese E-Mail-Adresse werden dann Erinnerungen geschickt, wenn ein Zertifikat abläuft oder wenn es Probleme bei der Verlängerung gibt. + +```bash +systemctl stop nginx && acme.sh --issue -d ws.example.com --standalone --server letsencrypt +acme.sh --install-cert -d ws.example.com --cert-file /etc/nginx/ssl/ws.example.com.cer --key-file /etc/nginx/ssl/ws.example.com.key --fullchain-file /etc/nginx/ssl/fullchain.pem --reloadcmd "systemctl reload nginx" +sudo systemctl restart nginx +``` + +Dein WebSocket Server ist nun mit einer SSL-Verschlüsselung ausgestattet. In der Konfiguration von Laravel muss nun der Port auf `443` geändert werden. + +## Ergebnis -Ihr WebSocket Server ist nun mit einer SSL-Verschlüsselung ausgestattet. In der Konfiguration von Laravel muss nun der Port auf '443' geändert werden. +Soketi wurde nun erfolgreich installiert und mit SSL-Zertifikat eingerichtet. Wenn du `ws.example.com` in einem Webbrowser eingibst, sollte dort "OK" erscheinen, was bedeutet, dass der WebSocket-Server erreichbar ist. ##### License: MIT diff --git a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md index 9fa17dbb0..3bf544d30 100644 --- a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md +++ b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md @@ -2,17 +2,18 @@ SPDX-License-Identifier: MIT path: "/tutorials/setup-soketi-websocket-server-behind-reverse-proxy" slug: "setup-soketi-websocket-server-behind-reverse-proxy" -date: "2024-08-04" +date: "2024-08-13" title: "Setting up a Soketi WebSocket Server behind a Reverse Proxy (NGINX)" short_description: "In this tutorial, you will learn how to set up and operate a Soketi WebSocket server behind an NGINX-based reverse proxy server." tags: ["WebSockets", "NGINX"] author: "crocodile2024" author_link: "https://github.com/crocodile2024" -author_img: "" +author_img: "https://avatars.githubusercontent.com/u/171804404" author_description: "" language: "en" -available_languages: ["de"] -header_img: "header-1" +available_languages: ["en", "de"] +header_img: "header-5" +cta: "cloud" --- ## Introduction @@ -22,63 +23,63 @@ In this tutorial, you will learn how to operate a Soketi WebSocket server behind Official Documentation: [https://docs.soketi.app/](https://docs.soketi.app/)
Project Website: [https://soketi.app/](https://soketi.app/) -**Requirement** +**Prerequisites** -* You need a domain name (a subdomain is sufficient) +* Domain name (a subdomain is sufficient) * Some experience with NodeJS and NPM -* A server (for example, in the [Hetzner Cloud](https://hetzner.cloud)) +* A server (for example, with [Hetzner Cloud](https://hetzner.cloud)) + * Debian 12 or Ubuntu 24.04 as operating system + * SSH key is recommended (see [this article](https://community.hetzner.com/tutorials/howto-ssh-key)) + * Access to the root user or a user with sudo permissions -## Step 1 - Order a new cloud server +**Example terminology** -* Log in to the [Hetzner Cloud Console](https://console.hetzner.cloud). -* Create a new project if you want, and name it as you wish. -* Choose a location and a server model. -* Click on "Add Server". In this tutorial, I use the Debian 12 operating system. -* No need to enter anything in the cloud config. -* Select your SSH key. - * You can read [this article](https://help.github.com/en/enterprise/2.16/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) if you need help creating an SSH key. -* Enter the name of your server in the `name` field (ws.example.de). -* Click on `Order for a fee`. +* Domain: `ws.example.com` +* IPv4: `203.0.113.1` +* IPv6: `2001:db8:1234::1` -## Step 2 - Set up DNS +## Step 1 - Install updates and necessary packages -You need a DNS entry that points to the server you ordered in step 1. This is necessary for an SSL certificate to be issued to you. - -Your DNS configuration should look like this: - -``` -# Name Type Value -ws IN A 10.0.0.1 -ws IN AAAA 2001:db8:1234::1 -``` - -## Step 3 - Install updates and necessary packages - -Wait a moment until your ordered server is installed. Once completed, you can connect to the server via SSH using your IP address or the subdomain set in step 2 (here ws.example.de). +Connect to the server via SSH using your IP address. Update package lists and install updates: -`apt update && apt upgrade -y` +```bash +sudo apt update && sudo apt upgrade -y +``` Then restart the server to load any updated kernel. Next, install all necessary packages: -`apt-get install git python3 gcc build-essential nodejs npm` +* Install prerequisites + ```bash + sudo apt install git python3 gcc build-essential apparmor nginx + ``` -If you are using a server in the Hetzner Cloud, you need to install the `apparmor` package. Otherwise, you will encounter issues later in this tutorial. +* Install NodeJS + ```bash + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash + source ~/.bashrc + nvm install 18 && nvm use 18 + ``` -`apt-get install apparmor` +* Install the two NodeJS packages `soketi` and `pm2`: + ```bash + npm install -g @soketi/soketi + npm install -g pm2 + ``` -Next, install the two NodeJS packages soketi and pm2: +## Step 2 - Create configuration for Soketi -`npm install -g @soketi/soketi` -`npm install -g pm2` +Create a new configuration file: -## Step 4 - Create configuration for Soketi +```bash +nano ~/config.json +``` -You can use the following configuration file as a basis and adjust it to your needs: +Add the following content and adjust it to your needs: -``` +```json { "host": "127.0.0.1", "port": 6001, @@ -100,84 +101,146 @@ You can use the following configuration file as a basis and adjust it to your ne } ``` +Save it with the key combination `CTRL`+`O`. + If this configuration file is used, no further configuration is required before the first start. -Copy the configuration you need. Then create a new file with a text editor in the SSH terminal: +## Step 3 - First start of the Soketi server (without PM2) -`nano config.json` +Now start the Soketi server by running the following command in a terminal: -Paste the copied content into the file and save it with the key combination `CTRL + O`. +```bash +soketi start --config="~/config.json" +``` -## Step 5 - First start of the Soketi server (without PM2): +## Step 4 - First test of the WebSocket server with Laravel 11 -Now start the Soketi server by running the following command in a terminal: +Make sure you have Laravel installed. -`soketi start --config=""` +
+If Laravel isn't installed yet, click here and install it now +
-## Step 6 - First test of the WebSocket server with Laravel 11: +```bash +sudo apt update && sudo apt install php php-{mbstring,xml,bcmath,mysql} mariadb-server +cd ~ && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +php composer-setup.php +echo 'alias composer="php ~/composer.phar"' >> ~/.bashrc && source ~/.bashrc +composer create-project --prefer-dist laravel/laravel ~/example +cd ~/example +``` -Change the following values in the .env file: +And setup a database: +```bash +sudo mysql +MariaDB [(none)]> CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'secure-password'; +MariaDB [(none)]> GRANT ALL PRIVILEGES ON laravel.* TO 'laravel'@'localhost'; +MariaDB [(none)]> CREATE DATABASE laravel; +MariaDB [(none)]> exit ``` -BROADCAST_DRIVER=pusher -PUSHER_APP_ID=your-app-id -PUSHER_APP_KEY=your-app-key -PUSHER_APP_SECRET=your-app-secret -PUSHER_APP_CLUSTER=mt1 + +Add the database information in the `~/example/.env` file: + +```env +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=laravel +DB_USERNAME=laravel +DB_PASSWORD=secure-password +``` + +Now run: + +```bash +cd ~/example && php artisan migrate ``` -Check the settings in the following file `config/broadcasting.php`: +
+ +------- + +Now, configure Soketi with Laravel. + +
+ +
+Change the following values in the `~/example/.env` file: + +> Add the same app ID, app key, and app secret, you also used in `~/config.json`. + +```env +BROADCAST_DRIVER=pusher +PUSHER_APP_ID=my-app-id +PUSHER_APP_KEY=my-app-key +PUSHER_APP_SECRET=my-app-secret +PUSHER_APP_CLUSTER=mt1 ``` -'connections' => [ - 'pusher' => [ - 'driver' => 'pusher', - 'key' => env('PUSHER_APP_KEY'), - 'secret' => env('PUSHER_APP_SECRET'), - 'app_id' => env('PUSHER_APP_ID'), - 'options' => [ - 'cluster' => env('PUSHER_APP_CLUSTER'), - 'useTLS' => true, + +Check the settings in the file `~/example/config/broadcasting.php`: + +```php + [ + 'pusher' => [ + 'driver' => 'pusher', + 'key' => env('PUSHER_APP_KEY'), + 'secret' => env('PUSHER_APP_SECRET'), + 'app_id' => env('PUSHER_APP_ID'), + 'options' => [ + 'cluster' => env('PUSHER_APP_CLUSTER'), + 'useTLS' => true, + ], ], + // other connections... ], - // other connections... -], +]; ``` -## Step 7 - Trigger first events +## Step 5 - Trigger first events You can now send the first events with your WebSocket server. -## Step 8 - Configure auto-start for the Soketi server: +## Step 6 - Configure auto-start for the Soketi server -To ensure the Soketi server starts automatically after a reboot of the cloud server, we need to configure `pm2`: +To ensure the Soketi server starts automatically after a reboot of the server, we need to configure `pm2`: Run the following commands: -- `pm2 start soketi --name WebSocket-Server -- start --config=""` -- `pm2 startup` (Then the autostart is activated) Follow the instructions on the screen. +```bash +pm2 start soketi --name WebSocket-Server -- start --config="~/config.json" +pm2 startup # This activates the autostart. Follow the instructions on the screen. +``` -## Step 9 - Set up reverse proxy +## Step 7 - Set up reverse proxy Now we need to set up the reverse proxy server. This will provide the SSL connection and then forward it to the soketi server. Create a new file in the `/etc/nginx/sites-available/` directory. -`mkdir /etc/nginx/ssl` -`nano /etc/nginx/sites-available/soketi` +```bash +sudo mkdir /etc/nginx/ssl +sudo nano /etc/nginx/sites-available/soketi +``` Add the following content to the file: -``` +> Replace `ws.example.com` with your own domain. + +```nginx server { listen 443 ssl; - server_name ws.example.de; + server_name ws.example.com; - ssl_certificate /etc/nginx/ssl/ws.example.de.cer; - ssl_certificate_key /etc/nginx/ssl/ws.example.de.key; + ssl_certificate /etc/nginx/ssl/ws.example.com.cer; + ssl_certificate_key /etc/nginx/ssl/ws.example.com.key; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; location / { - proxy_pass http://localhost:6001; # Replace the port if soketi is running on a different port + proxy_pass http://localhost:6001; # Replace the port if Soketi is running on a different port proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; @@ -190,7 +253,7 @@ server { server { listen 80; - server_name ws.example.de; + server_name ws.example.com; location / { return 301 https://$host$request_uri; @@ -198,23 +261,76 @@ server { } ``` -## Step 10 - Create SSL certificate +
-To create the certificate, we use the shell script `acme.sh`. Install it with the following command: +
+Click here if you don't want to setup SSL +
-`curl https://get.acme.sh | sh -s email=` +*Replace `203.0.113.1` with your own IP address.* -You will receive reminders at this email address when a certificate expires or if there are issues with renewal. +```nginx +server { + listen 80; + server_name 203.0.113.1; + + location / { + proxy_pass http://localhost:6001; # Replace the port if soketi is running on a different port + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} +``` +
+
+ +
+ +```bash +sudo ln -s /etc/nginx/sites-available/soketi /etc/nginx/sites-enabled/soketi +sudo rm /etc/nginx/sites-available/default && sudo rm /etc/nginx/sites-enabled/default +sudo nginx -t +sudo systemctl restart nginx +``` + +## Step 8 - Create SSL certificate + +Before you create an SSL certificate, make sure you have DNS entries that point the IP addresses of you server to your domain name. + +Your DNS configuration should look like this: + +```shellsession +# Name Type Value +ws.example.com IN A 203.0.113.1 +ws.example.com IN AAAA 2001:db8:1234::1 ``` -systemctl stop nginx && acme.sh --issue -d ws.example.de --standalone --server letsencrypt -ln -s /etc/nginx/sites-available/ws /etc/nginx/sites-enabled/ws -acme.sh --install-cert -d ws.example.de --cert-file /etc/nginx/ssl/ws.example.de.cer --key-file /etc/nginx/ssl/ws.example.de.key --fullchain-file /etc/nginx/ssl/fullchain.pem --reloadcmd "systemctl reload nginx" -systemctl start nginx + +If `dig ws.example.com` shows the correct IP address, you can create the certificate. Propagation can take a while. + +To create the certificate, we use the shell script `acme.sh`. Install it with the following command: + +```bash +curl https://get.acme.sh | sh -s email= ``` -## Done +You will receive reminders at this email address when a certificate expires or if there are issues with renewal. + +```bash +systemctl stop nginx && acme.sh --issue -d ws.example.com --standalone --server letsencrypt +acme.sh --install-cert -d ws.example.com --cert-file /etc/nginx/ssl/ws.example.com.cer --key-file /etc/nginx/ssl/ws.example.com.key --fullchain-file /etc/nginx/ssl/fullchain.pem --reloadcmd "systemctl reload nginx" +sudo systemctl restart nginx +``` Your WebSocket server is now equipped with SSL encryption. In the Laravel configuration, you need to change the port to `443`. +## Conclusion + +You have successfully installed Soketi and setup an SSL certificate. When you access `ws.example.com` in a web browser, you should get "OK" which means that the web socket is available. + ##### License: MIT From ee9ccf4986b5c7989c59b94bfa08b013b2c98cd0 Mon Sep 17 00:00:00 2001 From: crocodile2024 <171804404+crocodile2024@users.noreply.github.com> Date: Sun, 18 Aug 2024 23:45:46 +0200 Subject: [PATCH 5/6] Added License --- .../01.de.md | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md index b432c7a53..6deafd83e 100644 --- a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md +++ b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.de.md @@ -2,7 +2,7 @@ SPDX-License-Identifier: MIT path: "/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/de" slug: "setup-soketi-websocket-server-behind-reverse-proxy" -date: "2024-08-13" +date: "2024-08-18" title: "Installation eines Soketi WebSocket-Servers hinter einem Reverse-Proxy-Server (NGINX)" short_description: "Dieses Tutorial erklärt, wie man einen Soketi WebSocket-Server hinter einem Reverse-Proxy-Server, auf der Basis eines NGINX-Servers, einrichtet und betreibt." tags: ["WebSockets", "NGINX"] @@ -334,3 +334,32 @@ Dein WebSocket Server ist nun mit einer SSL-Verschlüsselung ausgestattet. In de Soketi wurde nun erfolgreich installiert und mit SSL-Zertifikat eingerichtet. Wenn du `ws.example.com` in einem Webbrowser eingibst, sollte dort "OK" erscheinen, was bedeutet, dass der WebSocket-Server erreichbar ist. ##### License: MIT + + From 30d65628896fb53a1bbc860e5002d91b478de662 Mon Sep 17 00:00:00 2001 From: crocodile2024 <171804404+crocodile2024@users.noreply.github.com> Date: Sun, 18 Aug 2024 23:46:40 +0200 Subject: [PATCH 6/6] Added License --- .../01.en.md | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md index 3bf544d30..4e658b5d8 100644 --- a/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md +++ b/tutorials/setup-soketi-websocket-server-behind-reverse-proxy/01.en.md @@ -2,7 +2,7 @@ SPDX-License-Identifier: MIT path: "/tutorials/setup-soketi-websocket-server-behind-reverse-proxy" slug: "setup-soketi-websocket-server-behind-reverse-proxy" -date: "2024-08-13" +date: "2024-08-18" title: "Setting up a Soketi WebSocket Server behind a Reverse Proxy (NGINX)" short_description: "In this tutorial, you will learn how to set up and operate a Soketi WebSocket server behind an NGINX-based reverse proxy server." tags: ["WebSockets", "NGINX"] @@ -334,3 +334,30 @@ Your WebSocket server is now equipped with SSL encryption. In the Laravel config You have successfully installed Soketi and setup an SSL certificate. When you access `ws.example.com` in a web browser, you should get "OK" which means that the web socket is available. ##### License: MIT + +