#URLs showing as https://http//localhost on production (Laravel 12 + Nginx + Dokploy)

1 messages · Page 1 of 1 (latest)

tawny crow
#

Hey everyone 👋

I’m running a new Laravel 12 app in production (deployed via Dokploy on a Hetzner VPS), and I’m facing a strange URL issue . Laravel sometimes generates links like:

https://http//localhost/register

Here’s what I’ve already checked:

✅ APP_URL=https://offline.ielts2go.com in .env

✅ URL::forceScheme('https') and URL::forceRootUrl(config('app.url')) in AppServiceProvider

✅ Cleared and re-cached configs: php artisan config:clear and config:cache

✅ HTTPS works fine on production

Here’s my current AppServiceProvider (relevant part):

if ($this->app->environment('production')) {
            // Force HTTPS scheme
            URL::forceScheme('https');
            $this->app['request']->server->set('HTTPS', true);
            // Ensure APP_URL is clean
            $appUrl = rtrim(config('app.url'), '/');
            // Force Laravel to use your configured domain as root
            if (!empty($appUrl)) {
                URL::forceRootUrl($appUrl);
            }
        }

Even though everything looks correct, Laravel still occasionally builds malformed URLs.
Has anyone run into this before, or know if URL::forceRootUrl() could conflict with something like the server headers or APP_URL parsing?

Thanks in advance 🙏

timber merlin
#

Have you set up trusted proxies such that forwarded-host-headers are read (if you have a load balancer or similar)?

#

You should also not have to use forceSchema if that is configured correctly, since x-forwarded-proto would say it should use https for links.