#Fetching user IP always returns 127.0.0.1 in production

24 messages · Page 1 of 1 (latest)

white hornet
#

I'm currently trying to fetch the auth user IP in a controller.

I've tried:

$request->server('REMOTE_ADDR')
$request->getClientIp()
$request->ip()

but they always return 127.0.0.1 . For reference, I'm using a standard digitalocean server deployed with forge.

Why is this happening?

lusty falcon
white hornet
lusty falcon
#

The request to your Laravel app is being proxied

white hornet
novel vale
#

You might see this if you check your nginx (or equivalent) access logs

white hornet
novel vale
#

If you have a proxy before that step, you should see that same IP for every request I think

#

Note that there may be more than one IP per row, if the proxies add their IP

#

If your backend is not reachable (no public url/ip) by anything except your proxy/load balancer, you can put '*' in the TrustedProxies settings

white hornet
#

does adding '*' to the trusted proxies list make my app vulnerable in some way?

novel vale
#

And is that nginx on the same server as the php app?

#

Or is that the proxy?

white hornet
#

If I have a proxy I didn't set it up intentionally. This is the server that the website is hosted on

#

this is a pretty standard deployment of forge > create droplet. The only thing different is that I have octane set up, I guess?

novel vale
#

Ok, I haven't used Forge but I'm sure there are some TrustedProxies information somewhere

white hornet
#

I guess I'll try adding 127.0.0.1 to trustedproxies, and if that doesn't work I'll just add '*'

white hornet
#

Update: Adding 127.0.0.1 to trustedproxies fixed the issue.

flint turtle
lusty falcon
white hornet