Nafis Ahmed
Nafis Ahmed

Reputation: 41

Laravel 9 not loading Vite & Tailwind Assets on Production

I am using Laravel 9 with tailwindcss and Vite on my development server to develop my project. On development server everything is working fine but when I uploaded my laravel project to production server running cpanel, none of my assets are loading properly. the error I'm getting :

Mixed Content: The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure script 'http://0.0.0.0:5173/@vite/client'. This request has been blocked; the content must be served over HTTPS.

Mixed Content: The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://0.0.0.0:5173/resources/css/app.css'. This request has been blocked; the content must be served over HTTPS.

I've tried to use URL::forceScheme('https'); in AppServiceProvider but to no avail.

Changed this line:

@vite(['resources/css/app.css', 'resources/js/app.js'])

in my guest.blade.php and app.blade.php file to this line:

<link href="{{ secure_asset('/resources/css/app.css') }}" rel="stylesheet">
<script src="{{ secure_asset('/resources/js/app.js') }}" defer></script>

but I'm getting this error:

    GET https://sarkercompanies.com/resources/resources/js/app.js 404 (Not Found) 12:28:20.818 
    GET https://sarkercompanies.com/resources/css/app.css net::ERR_ABORTED 404 (Not Found)

Please help as none of the solutions are working for me on production.

Upvotes: 2

Views: 2172

Answers (1)

Bene
Bene

Reputation: 56

Since I host my Laravel app on AWS with an Elastic Load Balancer configuring a trusted proxy fixed this problem for me: https://laravel.com/docs/9.x/requests#configuring-trusted-proxies

Consider trusting all proxies: https://laravel.com/docs/9.x/requests#trusting-all-proxies

I also forced Laravel to use the https-Scheme for URLs in the AppServiceProvider boot-method:

URL::forceScheme('https');

Upvotes: 0

Related Questions