file upload 401 unauthorized

Laravel 11.9, PHP 8.3, and Livewire 3.5,
I'm experiencing difficulties with file upload. Every time I try to upload a file, whether it's an image or a video, I encounter a "401 Unauthorized" error, which only appears in the production environment.

I've attempted multiple solutions from Google, but sadly, none have been effective, including some changes to Nginx configurations and other adjustments.

🚫 forceScheme https not working
  if (app()->isProduction()) {
    \URL::forceScheme('https');
    request()->server->set('HTTPS', request()->header('X-Forwarded-Proto', 'https') == 'https' ? 'on' : 'off');
  }


🚫 nginx config also not working
I set strict https in nginx.conf proxy_set_header X-Forwarded-Proto https; or correctly set up nginx ssl settings


🚫 Trusted proxies
->withMiddleware(function (Middleware $middleware) {
    $middleware->trustProxies(at: '*');
})


I've already tried all the fixes from here:
https://github.com/filamentphp/filament/discussions/9243
https://github.com/livewire/livewire/discussions/3084

this is so frustrating :/
but it works on my machine 😅
Solution
Ok, also try added before the location .php etc

location / {
try_files $uri $uri/ /index.php?$query_string;
}
Was this page helpful?