Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

caterpillar123's avatar

Run beyondcode/laravel-websockets in Azure App Service

Hello. Laravel mentiones beyondcode/laravel-websockets package (https://beyondco.de/docs/laravel-websockets/getting-started/introduction) in the official documentation as a free alternative to commercial broadcasting providers. I got it working locally, but then tried to deploy on Azure App Service and it doesn't work there anymore. When I run "php artisan websockets:serve", I simply don't see any connections, even though code in the browser is trying to connect (and it fails). I do see connections when I run "php artisan websockets:serve" locally.

I am aware that Azure App Service only exposes ports 80 and 443 to the outside world, but laravel-websockets listens on 6001. that's why I followed this section in their documentation - https://beyondco.de/docs/laravel-websockets/basic-usage/ssl#same-location-for-websockets-and-web-contents - and made sure websockets use port 443 like normal https requests. But internally nginx redirects them to "http://127.0.0.1:6001".

All of this works perfectly locally, but not on App Service. Can somebody think of reasons why laravel-websockets wouldn't work in Azure App Service?

Here's my nginx config that I use to make websockets work via port 443. It's mostly taken from the docs of laravel-websockets. Regular PHP requests work both locally and in App Service. It's just the websockets part that doesn't work in App Service:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name  _;

    index index.php index.html;
    root /app/public;

    # This location doesn't serve any files itself.
    # Instead it merely redirects HTTP requests to @web location and websocket requests to @ws location.
    # Source - laravel-websockets documentation - https://beyondco.de/docs/laravel-websockets/basic-usage/ssl
    location / {
        try_files /nonexistent @$type;
    }

    # @web location looks for a static file in "public" directory first. If there's no such file, then
    # request is sent to php and laravel
    location @web  {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_hide_header X-Powered-By;
        fastcgi_hide_header X-Ratelimit-Limit;
        fastcgi_hide_header X-Ratelimit-Remaining;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param HTTPS $fastcgi_param_https_check;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location @ws  {
        proxy_pass             http://127.0.0.1:6001;
        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;
    }

}
0 likes
0 replies

Please or to participate in this conversation.