Tengo el siguiente inconveniente. Tengo una aplicación desacoplada. El frontend por un lado y el socket por el otro. El siguiente problema es que mi socket funciona solo en local y no sé cómo hacerlo funcionar en un hosting compartido. Instalé el paquete laravel-websocket y mi backend está hecho en laravel y mi frontend en vuejs.
Esta es mi configuración en el config/broadcasting.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,
'encrypted' => true,
'host' => 'backtotal.test',
'port' => 6001,
'scheme' => 'https',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
],
Esta es mi configuración en el config/websocket.php
'ssl' => [
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
'verify_peer' => false,
'allow_self_signed' => true,
],
Variables en el archivo .env para los certificados:
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=/etc/ssl/certs/backtotal.crt
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=/etc/ssl/private/backtotal.key
Este es mi mi main.js en mi aplicación vuejs:
import Echo from 'laravel-echo';
window.Echo = new Echo({
broadcaster: 'pusher',
key: '***************',
cluster: 'tls',
forceTLS: true,
wsHost: 'backtotal.test',
wssPort: 6001,
wsPort: 6001,
scheme: 'https',
authEndpoint: `${config.url}/broadcasting/auth`,
enabledTransports: ['ws', 'wss'],
encrypted: false,
auth: {
headers: {
"Authorization": "Bearer " + token
}
}
});
He tratado de seguir este ejemplo que me encontré Laravel + Nuxt + Nginx
Pero siempre me muestra este error cuando lo monto en producción
Si alguien me pudiera ayudar o guiar, le agradecería mucho su ayuda.
ACTUALIZACIÓN
He leído que necesito hacer un ProxyReverse para que mi socket tenga salida por un puerto con ssl. Estos han sido los intentos de crear un ProxyReverse desde Apache y continuo sin poder acoplar mi socket con mi frontend con ssl:
INTENTO 1:
<VirtualHost *:443>
<Proxy *>
Require all granted
Allow from all
</Proxy>
SSLEngine on
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule .* wss://127.0.0.1:6001%{REQUEST_URI} [P]
ProxyPass / ws://127.0.0.1:6001
ProxyPassReverse / ws://127.0.0.1:6001
SSLCertificateFile /etc/ssl/certs/websocket.crt
SSLCertificateKeyFile /etc/ssl/private/websocket.key
</VirtualHost>
INTENTO 2:
<VirtualHost *:443>
Include /etc/apache2/default-ssl.conf
ServerName websocket.test
ServerAlias *.websocket.test
SSLEngine on
SSLCertificateFile /etc/ssl/certs/backtotal.crt
SSLCertificateKeyFile /etc/ssl/private/backtotal.key
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:6001/$1 [P,L]
ProxyPass / http://localhost:6001/
ProxyPassReverse / http://localhost:6001/
</VirtualHost>
INTENTO 3:
<VirtualHost *:443>
DocumentRoot /var/www/html/tastytotal/public
<Directory /var/www/html/tastytotal/public>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
ProxyPass /wss ws://127.0.0.1:6001 retry=3 keepalive=On
ProxyPassReverse /wss ws://127.0.0.1:6001 retry=3
</VirtualHost>
netstat -tulpn | grep LISTEN
me muestratcp 0 0 127.0.0.1:6001 0.0.0.0:* LISTEN 34527/php
es decir, el puerto está abierto y escuchando.nmap -p 6001 <host>
?PORT STATE SERVICE 6001/tcp filtered X11:1