phayes0289's avatar

Spatie Media Library Pro Using unsecure http on Production Server and Failing

I have developed a project that heavily relies on Spatie Media Library Pro. Everything works great on the development server (locally), but when I moved it to a public web server, it is failing to upload the temporary image. The following two errors occur as a result of taking the first step in uploading an image, which is moving the image to the temporary state.

[blocked] The page at https://demo.fireops.app/posts/edit/34 was not allowed to display insecure content from http://demo.fireops.app/livewire/upload-file?expires=1695051099&signature=176e4a92c2b337a94a3c388e122653fe867591cd99b34eda5b0fd9a2604f99c2.

and

XMLHttpRequest cannot load http://demo.fireops.app/livewire/upload-file?expires=1695051099&signature=176e4a92c2b337a94a3c388e122653fe867591cd99b34eda5b0fd9a2604f99c2 due to access control checks.

What can be causing it to use http instead of https? My APP-URL in the .env has https in it. Is this a software bug or a configuration bug? Any ideas on how I can resolve it?

0 likes
5 replies
LaryAI's avatar
Level 58

This issue is likely caused by the fact that the Spatie Media Library Pro package is generating URLs with the "http" protocol instead of "https" on your production server. To resolve this, you can try the following steps:

  1. Make sure that your production server is properly configured with an SSL certificate and is accessible via HTTPS. This is important to ensure secure communication between the server and the client.

  2. Check the configuration of your Laravel application. Verify that the APP_URL variable in your .env file is set to the correct HTTPS URL of your production server. For example, it should be something like APP_URL=https://example.com.

  3. Clear the application cache by running the following command in your terminal:

php artisan cache:clear
  1. If the issue persists, you may need to manually set the secure option in the configuration file of the Spatie Media Library Pro package. Locate the config/medialibrary.php file in your Laravel project and ensure that the secure option is set to true. If it is already set to true, try setting it to false and then back to true again.

  2. If none of the above steps resolve the issue, it's possible that there is a bug in the Spatie Media Library Pro package. In that case, you can try reaching out to the package maintainers for further assistance. You can open an issue on their GitHub repository or post a question on the Laracasts forum.

Please note that without access to your specific codebase and server configuration, it's difficult to provide an exact solution. The steps mentioned above are general troubleshooting steps that can help resolve issues related to using HTTP instead of HTTPS.

Snapey's avatar
Snapey
Best Answer
Level 122

If you are behind a proxy like Cloudflare then the traffic from the user to the proxy will use https but the traffic from the proxy to your server will use http

This causes routes that are generated automatically by the server to use the same protocol as the request that they recieved (ie, http).

The common way to fix this is to configure trusted proxies

https://laravel.com/docs/10.x/requests#configuring-trusted-proxies

1 like
phayes0289's avatar

@Snapey BIGO! I am using Cloudflare. I began thinking it was Cloudflare this AM and was going to try LetsEnrypts SSL to see if it makes a difference. Before I do that, I will look into Trusted Proxies.

Please or to participate in this conversation.