Trust proxies so HTTPS sticks

Behind one load balancer, trustProxies(at: '*') makes Laravel see HTTPS. Do not do that on a machine exposed directly.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/laravel-trust-proxies-https.md
Behind one load balancer, trustProxies(at: '*') makes Laravel see HTTPS. Do not do that on a machine exposed directly.
Do not do that on a machine exposed directly.
Do not set URL::forceScheme('https') and also forget the proxy.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Laravel trust proxies HTTPS” get an infinite redirect or a session cookie that will not stick. The app thinks the request is HTTP because the proxy terminated TLS. Generated URLs then use http, and SESSION_SECURE_COOKIE refuses to send the cookie. The deploy guide is the host. This page is the middleware.

TL;DR

  • Behind one load balancer, trustProxies(at: ’*’) makes Laravel see HTTPS.
  • Do not do that on a machine exposed directly.
  • Do not set URL::forceScheme('https') and also forget the proxy.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

On Laravel 11 and newer, in bootstrap/app.php:

php
->withMiddleware(function (Middleware $middleware) {
    $middleware->trustProxies(at: '*');
})

at: '*' trusts every proxy. That is right when the app is only reachable through the load balancer. It is wrong when the process is on a public port, because a client can send X-Forwarded-For and X-Forwarded-Proto itself.

APP_URL should still be the https URL users type. Trusting proxies does not replace it.

What to avoid#

Gotcha

Do not set URL::forceScheme('https') and also forget the proxy. You can end up with https URLs and a request object that still says the scheme is http. Fix the proxy headers first.

FAQ#

How do I trust proxies so HTTPS sticks?

Behind one load balancer, trustProxies(at: '*') makes Laravel see HTTPS. Do not do that on a machine exposed directly.

What goes wrong with Laravel trust proxies HTTPS?

Many developers get an infinite redirect or a session cookie that will not stick. Do not set URL::forceScheme('https') and also forget the proxy.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.