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
π« nginx config also not working
π« Trusted proxies
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:Jump to solution
Ok, also try added before the location .php etc
location / {
try_files $uri $uri/ /index.php?$query_string;
}...
23 Replies
Hang on a second, where is the disk for the file uploads?
im using
->disk('public')
also tried disk('local')
same errorOk was just checking it wasn't an S3 issue.
Ensure you have set
if (App::environment('production', 'development'))
{
URL::forceScheme('https');
}
in the AppServiceProvider too
php artisan storage:link
done β
ensure you link the storage
ensure your app_url matches the accessing url too.
yes, we already tried it
.env
app_url
matches β
but fileUpload still failing
We are using CloudFlare, and I read that it could be the problem. We haven't disabled it yet because it might break other sites hosted on our VPSStrange, I use cloudflare with apps deployed through ploi and forge. All works fine here.
i'll share the nginx config, gimme a minute
do you have a directory at
storage/livewire-tmp
, I'm thinking this might be a permissions issue on the server were the app (server user) can't create directories.not sure, lemme check
i could be wrong, but it everything else is setup correctly then that's the only thing coming to mind
You seem to be missing quite a bit in the fast-cgi compared to what I use
i.e.
SCRIPT_FILENAME and pass missing could cause it
and then public check chmod permissions
ok, i'll try both things, i'll be right back
directory was already set & got all the correct permissions
sadly issue persists
Does the file upload at all?
no
Solution
Ok, also try added before the location .php etc
location / {
try_files $uri $uri/ /index.php?$query_string;
}
lemme try
it works!!!!
working!!!
Welcomes!
thank you so muchhhhhhhh β₯
it was because of
try_files $uri $uri/ /index.php?q=$uri&$args;
you had a duplicated $uri and the uri/args is a bit messy
I donβt have much experience with Nginx, so I wouldnβt pick up on it. Thanks a lot once more! π₯
No problem