Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the IP of an HTTP request in a Laravel Vapor application?

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);

    }
like image 498
Nathan Avatar asked Sep 06 '25 03:09

Nathan


1 Answers

There is x-vapor-source-ip header in latest Vapor core package (vapor-core:v2.2.1) which exposes Lambda's sourceIp property in order to get the client's real ip safely.

You can retrieve the ip:

Request::header('x-vapor-source-ip')
like image 181
mikkokut Avatar answered Sep 07 '25 22:09

mikkokut