Livewire's /livewire/upload-file
endpoint returns HttpException
with status code 401 when attempting to upload file in production environment.
On localhost it works fine. On production environment we use haproxy load balancer.
The exception is thrown in Livevire's FileUploadController.php:handle()
on line 21:
abort_unless(request()->hasValidSignature(), 401);
For security reasons Livewire checks if the request is not manupulated by comparing requested URL with actual URL.
If you send HTTPS request to your app and your production environment uses load balancer that communicates with your application server via HTTP (not HTTPS) the URL comparison will fail and hasValidSignature()
returns false.
To fix this update your load balancer settings to add header X-Forwarded-Proto
with value https
to each request coming to your app.