I facing same issue right now, here the AI answer:
To run Laravel Octane with Nginx, you need to configure Nginx to act as a reverse proxy, forwarding requests to the Octane server (which is typically running on a separate port, like 8000). This setup allows Nginx to handle static assets and pass dynamic requests to Octane for processing.
Here's a breakdown of the process:
Install and Configure Octane:
Install Octane: composer require laravel/octane
Install RoadRunner (or Swoole): Octane uses either RoadRunner or Swoole as its application server. You'll need to install the appropriate binary for your chosen server.
Configure Octane: Octane creates a configuration file (octane.yaml) where you can specify the server (RoadRunner or Swoole), port, and other settings.
Configure Nginx:
Install Nginx: Ensure Nginx is installed on your server.
Create a Virtual Host: Create a new virtual host configuration file (e.g., /etc/nginx/sites-available/your_app) for your Laravel application.
Configure server block:
Specify the server name (your domain) and root directory (the public directory of your Laravel application).
Set server_tokens off; to hide server version information.
Configure location blocks:
Static Assets: Use try_files to serve static assets directly from the public directory.
Dynamic Requests: Use a named location (e.g., @octane) to proxy dynamic requests to the Octane server.
Favicon and Robots.txt: Configure separate location blocks for favicon.ico and robots.txt to optimize logging.
Configure @octane location:
Set proxy_http_version 1.1;
Set appropriate proxy_set_header directives to forward request information to Octane.
Use proxy_pass to forward requests to the Octane server's address and port (e.g., http://127.0.0.1:8000).
Enable the Virtual Host: Create a symbolic link in sites-enabled to activate the virtual host.
Test Nginx Configuration: sudo nginx -t
Reload Nginx: sudo systemctl reload nginx
Start the Octane Server:
Use the php artisan octane:start command to start the Octane server. You can specify options like the server type (RoadRunner or Swoole), port, workers, and maximum requests.