Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Jenry Mazariegos
Jenry Mazariegos

Posted on

     

Laravel Reverb in Production Environment

Hi, before starting this tutorial, I recommend readingThe Ultimate Guide to Laravel Reverb: Real-Time Notifications, as this tutorial assumes you already have Laravel Reverb set up and working locally.

Basic Concepts

First, it’s essential to understand how port connections work. Laravel Reverb uses two ports: one for connecting to the WebSocket and another for server communication.

In this case, we will use port 443 for public access. This port is crucial for users accessing the webpage as it handles secure HTTPS traffic.

For WebSocket communication, we will use port 6001. This port doesn’t need to be publicly accessible since it is only used internally by the server for real-time communication.

Configurations

Now, let's modify out.env

REVERB_HOST="your.domain.com" # your domain name hereREVERB_PORT=443 # The public port used by all clients on your websiteREVERB_SCHEME=https # Required for prod environment
Enter fullscreen modeExit fullscreen mode

Them in your nginx configuration put the next code.

server {  listen 443 ssl;  listen [::]:443 ssl;  server_name your.server.name;  {{ssl_certificate_key}}  {{ssl_certificate}} location /app/ {    proxy_http_version 1.1;    proxy_set_header Host $http_host;    proxy_set_header Scheme $scheme;    proxy_set_header SERVER_PORT $server_port;    proxy_set_header REMOTE_ADDR $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    proxy_set_header Upgrade $http_upgrade;    proxy_set_header Connection "Upgrade";    proxy_pass http://0.0.0.0:6001;}location /apps {    proxy_http_version 1.1;    proxy_set_header Host $http_host;    proxy_set_header Scheme $scheme;    proxy_set_header SERVER_PORT $server_port;    proxy_set_header REMOTE_ADDR $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    proxy_set_header Upgrade $http_upgrade;    proxy_set_header Connection "Upgrade";    proxy_pass http://0.0.0.0:6001;}}
Enter fullscreen modeExit fullscreen mode

What we do here? This setup securely redirects all WebSocket traffic from the public-facing port 443 to the internal WebSocket server on port 6001, enabling secure and efficient real-time communication between clients and the server.

For Apache configurations you can read these posts.

After completing the configuration, the next step is to start the service. In a real-world scenario, you should use a process manager, such asSupervisor, to ensure the service runs continuously and restarts automatically if needed.

For testing purposes, however, you can run the command manually from the command line.

php artisan reverb:start --port=6001 --debug
Enter fullscreen modeExit fullscreen mode

Now we are ready to work with WebSocket in a production environment. Remember to restart the service and clear the cache before testing to ensure everything runs smoothly.

A post that can help us gain a deeper understanding of this topic.

I hope this helps you get started! See you in the next post.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Web and mobile developer, always in search of knowledge
  • Education
    Guatemala
  • Work
    Developer
  • Joined

More fromJenry Mazariegos

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp