Common Nginx Error Log Pattern (PHP / Laravel Octane)
When upstream sockets, timeouts, body limits, or Docker DNS rules are misconfigured for PHP / Laravel Octane, Nginx typically records an entry matching the log line below inside /var/log/nginx/error.log:
2026/11/22 16:04:11 [error] 3190#3190: *1205 upstream prematurely closed connection while reading upstream, client: 192.0.2.88, server: api.laravelapp.com, request: "GET /app/reverb-app-key?protocol=7&client=js HTTP/1.1", upstream: "http://127.0.0.1:8080/app/reverb-app-key", host: "api.laravelapp.com"
Reverse Proxy Architecture & Header Forwarding for PHP / Laravel Octane
Modern high-throughput Laravel 11 and 12 deployments increasingly replace traditional PHP-FPM with Laravel Octane (backed by FrankenPHP, Swoole, or RoadRunner on port 8000) paired with Laravel Reverb; Laravel's first-party WebSocket server listening on port 8080. Because both Octane and Reverb are long-running HTTP/WebSocket daemons, Nginx sits in front as an HTTP/1.1 reverse proxy rather than a FastCGI gateway.
Running Octane and Reverb behind a single HTTPS domain requires splitting traffic cleanly by location path while serving static public/ assets directly from disk. Regular application routes proxy to Octane on 127.0.0.1:8000, whereas Reverb's Pusher-compatible WebSocket handshake endpoint (/app) and HTTP broadcast trigger API (/apps) proxy to 127.0.0.1:8080 with Upgrade headers and an extended 3600-second read timeout.
A classic Laravel production bug occurs when TrustProxies is left unconfigured after putting Nginx TLS in front of Octane: signed URLs (URL::temporarySignedRoute), pagination links, and Sanctum secure cookies break because Laravel inspects the plain HTTP loopback connection instead of Nginx's X-Forwarded-Proto: https header. Configuring $middleware->trustProxies(at: '*') or trusting Nginx's exact IP in bootstrap/app.php resolves scheme detection across every route.
Separating static public assets via try_files $uri $uri/ @octane ensures Nginx serves CSS, JS, and uploaded storage images at C speed without occupying Octane PHP workers, while clean proxy_set_header rules keep Laravel Echo WebSocket connections rock-solid across mobile networks and corporate proxies.
In production Laravel Octane and Reverb environments, separate your Nginx access and error log streams or include $upstream_addr in your log format so you can immediately distinguish HTTP API latency on Octane port 8000 from WebSocket churn on Reverb port 8080. Pair Nginx reload safety (sudo nginx -t && sudo systemctl reload nginx) with php artisan octane:reload during deployments so active Reverb WebSocket subscribers stay connected while Octane PHP workers pick up new release code cleanly.
Step-by-Step Nginx & PHP / Laravel Octane Deployment Guide
Apply the Nginx server block above alongside these upstream framework trust-proxy settings so HTTPS detection, real client IPs, and reload safety work reliably in production.
1Route Static Assets, Octane (8000), and Reverb WebSockets (8080) in Nginx
/etc/nginx/sites-available/api.laravelapp.com.confCombine the generated HTTPS server block with a @octane fallback for Laravel public files and dedicated /app and /apps location blocks pointing to Laravel Reverb on port 8080 with WebSocket Upgrade headers.
/etc/nginx/sites-available/api.laravelapp.com.confnginxroot /var/www/laravel/public; location / { try_files $uri $uri/ @octane; } location @octane { proxy_pass http://127.0.0.1:8000; proxy_http_version 1.1; 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; } # Laravel Reverb WebSocket Server (port 8080) location /app { proxy_pass http://127.0.0.1:8080; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 3600s; proxy_send_timeout 3600s; }2Configure TrustProxies in Laravel 11/12 Bootstrap
bootstrap/app.phpTell Laravel to trust Nginx's X-Forwarded-* headers so request()->secure(), signed verification emails, and Sanctum cookies recognize HTTPS accurately behind Nginx TLS termination.
bootstrap/app.phpphp<?php use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Middleware; use Illuminate\Http\Request; return Application::configure(basePath: dirname(__DIR__)) ->withMiddleware(function (Middleware $middleware) { $middleware->trustProxies( at: ['127.0.0.1'], headers: Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO ); }) ->create();3Align Laravel Reverb & Echo Environment Variables for HTTPS Port 443
.envRun Reverb internally on HTTP port 8080 while instructing frontend Laravel Echo clients to connect via WSS on port 443 through Nginx; never expose port 8080 directly to the internet.
.envdotenvREVERB_SERVER_HOST=127.0.0.1 REVERB_SERVER_PORT=8080 REVERB_HOST=api.laravelapp.com REVERB_PORT=443 REVERB_SCHEME=https OCTANE_HTTPS=true4Supervise Octane and Reverb Workers With Supervisor and Reload Nginx
terminalKeep both Octane and Reverb monitored under Supervisor (or systemd) with clean reload hooks, then validate Nginx syntax before reloading.
terminalbashphp artisan octane:start --server=frankenphp --host=127.0.0.1 --port=8000 php artisan reverb:start --host=127.0.0.1 --port=8080 sudo nginx -t && sudo systemctl reload nginx
Common PHP / Laravel Octane Nginx Reverse Proxy Pitfalls
Review these three production failure modes before reloading Nginx on staging or live servers.
Reverb /app Path Colliding With a Laravel Application Route Named /app
Because Reverb uses /app/{appKey} for WebSocket handshakes, if your Laravel web app already serves a SPA or dashboard under /app, Nginx sends dashboard page loads to Reverb (returning 404). Host Reverb on a dedicated subdomain like ws.laravelapp.com when /app is already taken.
Forgetting /apps Location Block for Server-Side Broadcast Triggers
If another microservice triggers Reverb broadcasts over your public domain, Reverb listens on /apps/{appId}/events. If you only proxy /app without /apps, WebSocket clients connect fine while external HTTP broadcast triggers fail with 404.
Leaving proxy_read_timeout at 60s for Laravel Echo Connections
Idle Laravel Echo sockets get severed by Nginx every 60 seconds unless proxy_read_timeout is raised to 3600s or Reverb's ping_interval stays well below Nginx's timeout threshold.
Complete Your Deployment With Matching Docker Compose & CORS Tools
Pair this Nginx reverse proxy block with healthcheck-gated Docker Compose orchestration and verified browser CORS headers:
Generate a Docker Compose stack for Laravel Octane, PostgreSQL 16, Redis 7, and Laravel Reverb WebSockets with pg_isready healthchecks and firewall safety.
Simulate and fix CORS preflight errors between Laravel 11/12 APIs and React Vite on port 5173. Generate config/cors.php with credentials and header rules.
Frequently Asked Questions
- Do I still need PHP-FPM when running Laravel Octane behind Nginx?
- No. Octane boots your Laravel application once in memory via FrankenPHP, Swoole, or RoadRunner and speaks HTTP directly to Nginx via proxy_pass, completely replacing fastcgi_pass and PHP-FPM for that site.
- Why do Laravel signed routes return 403 Invalid Signature behind Nginx?
- Laravel generates signed URLs using the incoming scheme and host. If TrustProxies is not configured in bootstrap/app.php or Nginx does not forward X-Forwarded-Proto $scheme and Host $host, Laravel validates an https:// signature against an http:// request URL and rejects it with 403.
- Should Reverb run on a separate subdomain like ws.example.com?
- Using a dedicated subdomain like ws.example.com avoids any chance of /app route collisions with your main Laravel application and allows independent connection limits and file-descriptor tuning in Nginx.
- How many concurrent WebSocket connections can Nginx proxy to Laravel Reverb?
- Each proxied WebSocket uses two file descriptors (client + upstream). Increase worker_connections (e.g., 16384) and worker_rlimit_nofile in /etc/nginx/nginx.conf alongside ulimit -n on your Reverb Supervisor process to support thousands of concurrent sockets.
Related Nginx Reverse Proxy Guides
Browse all 10 Nginx guides →Nginx Reverse Proxy Config for Socket.IO & WebSockets (Upgrade & 3600s)
Fix WebSocket 400 errors and 60-second disconnects in Nginx for Socket.IO and ws servers. Generate Upgrade, Connection map, and 3600s proxy_read_timeout blocks.
Nginx Config for React (Vite) SPA + Same-Origin /api/ Proxy (Zero CORS)
Serve a built React Vite dist/ SPA at / with try_files history fallback while proxying /api/ to your backend on the same Nginx domain to eliminate CORS.
Nginx Reverse Proxy for Docker Compose Services (127.0.0.11 DNS Resolver)
Prevent 502 Bad Gateway and Nginx startup crashes in Docker Compose using resolver 127.0.0.11 and variable proxy_pass for dynamic container restarts.
Nginx Multi-Service Subpath Routing Config (/api/, /auth/ & /ws/)
Route /api/, /auth/, and /ws/ microservices to separate backend ports under one Nginx HTTPS domain. Master trailing-slash prefix stripping and prevent 404s.