I recently moved a Laravel app from a server to Vapor. This app relies on logging request IP addresses using Request::ip()
, but since switching to Vapor, all IPs are logged as 127.0.0.1.
I have looked over the Trusted Proxy docs at https://laravel.com/docs/5.6/requests#configuring-trusted-proxies but we do not have a load balancer set up, so this solution does not appear relevant. I suspect this IP address is coming from the Amazon API Gateway.
How do we get the actual client IP of incoming requests in an app deployed on Vapor?
A minimal example of how we use the IP address is below:
public function store(Request $request)
{
$workerIP = $request->ip();
$worker = Worker::create(['ip_address' => $workerIP]);
return view('workers.show')->withWorker($worker);
}
"we do not have a load balancer set up" Yes, you do. The API Gateway is, fundamentally, a proxy of exactly the sort that the trusted proxy configuration is intended for.
Set 'proxies' => '*'
in your config/trustedproxy.php
file and you should start seeing the right IP addresses.