Laravel 9 未加载 Vite & Tailwind Assets on Production



我在开发服务器上使用带有tailwindcss和Vite的Laravel 9来开发我的项目。在开发服务器上,一切都很好,但当我将我的laravel项目上传到运行cpanel的生产服务器时,我的资产都没有正确加载。我得到的错误:

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.

我尝试过使用URL::forceScheme('https'(;在AppServiceProvider中,但无效。

更改此行:

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

在我的guest.blade.php和app.blade.hp文件中

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

但我得到了这个错误:

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)

请帮忙,因为没有一个解决方案对我的生产有效。

由于我在AWS上托管我的Laravel应用程序,并使用配置受信任代理的弹性负载均衡器为我解决了这个问题:https://laravel.com/docs/9.x/requests#configuring-可信代理

请考虑信任所有代理:https://laravel.com/docs/9.x/requests#trusting-所有代理

我还强迫Laravel在AppServiceProvider引导方法中使用https方案:

URL::forceScheme('https');

最新更新