Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ghostrockz3d's avatar

Laravel selects a wrong IP on Trusted Proxies

I'm using caddy as a webserver and laravel octane to supercharge my app

and here's my trust proxies settings $middleware->trustProxies(at: '*', headers: Request::HEADER_X_FORWARDED_FOR);

and here's the $request->header() values

'x-forwarded-for' => array ( 0 => '1.1.1.1, 8.8.8.8', ),

the 1.1.1. is the client ip and 8.8.8.8 is the cdn ip the problem is when I use $request->ip() I get 8.8.8.8 instead of 1.1.1.1 how can I fix that ?

0 likes
3 replies
ghostrockz3d's avatar

@s4muel Thank you for your response

Here's the $request->ips() output : array ( 0 => '8.8.8.8' (cdn ip ), 1 => '1.1.1.1' (client/user ip), )

Which is really weird why would the cdn ip get the first in the array ? based on this header 'x-forwarded-for' => array ( 0 => '1.1.1.1, 8.8.8.8', ),

If you had any idea I would appreciate the help

ghostrockz3d's avatar
ghostrockz3d
OP
Best Answer
Level 3

OK Found the solution You have to put your CDN IPs in the $middleware->trustProxies(at: 192.168.1./24', headers: Request::HEADER_X_FORWARDED_FOR);

otherwise it wouldn't count them as safe and would ignore them

Please or to participate in this conversation.