1

I deployed a Laravel 9 app (with Jetstream/Livewire) to DigitalOcean using their "App" service from GitHub. Deployment was smooth and CI/CD works fine.

When viewing the application in the browser, I noticed that the assets (CSS and JS) are being served with a HTTP URL. None of the modern browsers like this (called "mixed content"). So I configured Vite (/vite.config.js) to compile the assets using HTTPS. Now they work.

However, Laravel itself insists on using HTTP when building URL's within the Blade templates (url() and route()). For instance, on the login page, the login form action is http://mywebsite.com.

I have tried:

  1. Editing AppServiceProvider.php and adding \Illuminate\Support\Facades\URL::forceScheme('https'); to the boot() method
  2. Setting proxies to '*' in TrustProxies middleware
  3. Adding all of the CloudFlare IP's to the proxies property of TrustProxies middleware
  4. Setting APP_URL and ASSET_URL to https://mywebsite.com in .env
  5. Clearing the caches after changing the settings by php artisan optimize:clear

But none of this has helped and the forms (and other URL's) are generated under the HTTP scheme. I am guessing that the reverse proxy setup is confusing Laravel. What are the right Laravel settings to help it play nicely with DigitalOcean App service (which uses Heroku and CloudFlare? for deployment)?

Aydin4ik
  • 1,782
  • 1
  • 14
  • 19
  • change the app_url to https in your .env – N69S Jan 03 '23 at 08:20
  • you mentioned what you tried but can you share how you tried it? solution 1 should work, and solution 2 would work if you app is behind a proxy of some sort (and 3 would work if your app is behind cloudflare proxies specifically). however there might be something in your specific implementation that is preventing them from working – apokryfos Jan 03 '23 at 08:49
  • @N69S Already done that and added it to the question - thanks! – Aydin4ik Jan 03 '23 at 09:00
  • @apokryfos I just edited the files and added the noted details in them (edited the original question to make it clearer). And it does not work. The "proxy of some sort" is the part I am trying to clarify - what sort of a proxy does DigitalOcean App service use, and how do I marry it to Laravel? – Aydin4ik Jan 03 '23 at 09:02

1 Answers1

1

Turns out, forceScheme() should be added as

\URL::forceScheme('https');

and not as

\Illuminate\Support\Facades\URL::forceScheme('https');

Because it lives in the Illuminate\Routing\UrlGenerator class. Some answer in the internets has mislead me... Don't let is mislead you!

Aydin4ik
  • 1,782
  • 1
  • 14
  • 19
  • I don't know how this makes sense, `\URL` is an alias of `\Illuminate\Support\Facades\URL` (as declared in https://github.com/laravel/framework/blob/9.x/src/Illuminate/Support/Facades/Facade.php#L293 and used in https://github.com/laravel/laravel/blob/9.x/config/app.php) so it should be functionally identical – apokryfos Jan 04 '23 at 06:20
  • Don't know ‍♂️ But it works now :) – Aydin4ik Jan 06 '23 at 17:03