0

I ran into an issue when trying to upload files using Livewire on my production server. The server responded with 401 Unauthorized.

My setup includes:

  • Cloudflare with Flexible SSL (Browser → encrypted → Cloudflare → not encrypted → Origin Server).
  • Nginx as the reverse proxy and PHP-FPM.
  • Running inside Docker containers.

I expected the uploads to succeed and the files to be stored correctly. However, Laravel (Livewire) rejected the request because the signature verification failed. I checked my session settings, Nginx configuration, and Livewire temporary upload URLs to identify the cause.

I have already identified the cause and resolved the issue, and I am posting the solution to help anyone facing the same problem.

1 Answer 1

1

The issue occurs because Livewire’s temporary file upload URLs are signed and include the request scheme (http or https) in the signature.

With Cloudflare Flexible SSL, the browser connects via HTTPS, but the request from Cloudflare to the origin server is HTTP. Laravel sees the request as HTTP, so the signature validation fails - 401 Unauthorized.

I fixed the problem by explicitly passing the HTTPS scheme to PHP-FPM in my Nginx configuration:

location ~ ^/index\.php(/|$) {
    fastcgi_pass php-fpm:9000;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_hide_header X-Powered-By;

    # Fix for Livewire signed URLs under Flexible SSL
    fastcgi_param REQUEST_SCHEME https;
    fastcgi_param HTTPS on;
}

After this change, Livewire generated URLs with the correct HTTPS scheme, and file uploads worked without any 401 errors.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.