Websockets over SSL behind nginx reverse proxy

Damn, that was hard work!

After having implemented websockets locally with not problems, the deploying to the production server costs me a fortune of time…

So, here is my configuration:

  • The site is running unter https://sola.gymgmunden.at
  • This reaches for the front server, which is running nginx as a proxy server
  • The „real“ webserver is, which is also running nginx, but as a reverse proxy for laravel octane, which is running on this same server. AND, since yesterday, on this server also runs the laravel-websocket server on port 6001.

So, how to get the client to establish the websocket connection, when publishing the webserver and the websocket server at the same port?


First of all, in the app.js file you have to set the wssPort to 443 and forceTLS to true.

Proxy Server

This is my proxy server, until now passed the web traffic to the reverse proxy. But now, this is the point where the traffic has to be divided into the „normal“ web traffic and the websocket traffic. And depending on the type, it will be forwarded differently:

Reverse Proxy + Websocket Server

This is the „real“ webserver, where nginx serves the application as reverse proxy for laravel octane, and the websocket server runs on port 6001.

All I had to change here was open the firewall for port 6001:

later edit:

I am not able to read any configuration value from the .env file, neither if I prefix it with MIX_ nor with require(‚dotenv‘).config(). So I had to find another solution to force TLS in production, but do not on local development: here is my updated configuration: