Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not detect IP Client #371

Closed
mcolominas opened this issue Aug 31, 2021 · 4 comments
Closed

Does not detect IP Client #371

mcolominas opened this issue Aug 31, 2021 · 4 comments

Comments

@mcolominas
Copy link

  • Octane Version: 1.0.11
  • Laravel Version: 8.57.0
  • PHP Version: 8.0.10
  • Server & Version: Swoole 4.7.1

Description:

When using Request::ip() and request()->ip() to get the client's ip, it returns the ip 127.0.0.1. I want to clarify, that laravel is running on a server with an associated domain, not on a local machine.

Steps To Reproduce:

routes/web.php

Route::get('/', function () {
    dd(Request::ip()); // "127.0.0.1"
});
@Namoshek
Copy link
Contributor

Are you using a reverse proxy like Nginx in front of Laravel Swoole?

@mcolominas
Copy link
Author

mcolominas commented Aug 31, 2021

I'm using apache2, this is the configuration

<VirtualHost *:443>
...
ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8082/
    ProxyPassReverse / http://127.0.0.1:8082/

    RemoteIPHeader X-Forwarded-For
    RemoteIPTrustedProxy 127.0.0.1
...
</VirtualHost>

@mcolominas
Copy link
Author

Sorry for the inconvenience, I have managed to fix it, I put the solution here in case someone else also happens the same.

The problem was that the proxy ip (127.0.0.1) was not set in the TrustProxies middleware.

This can be a common mistake among newbies who have never used a proxy, as the tutorials do not say anything about this middleware.

@nogamenofun98
Copy link

image

For anyone that want to know where to edit, here is the location, app\Http\Middleware\TrustProxies.php :D

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants