-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
How do I get the real ip? #599
Comments
sometimes or always? 2015-11-19 11:38 GMT+08:00 Alisson Cavalcante Agiani <
|
always when someone is behind a NAT |
this is what https://github.com/jshttp/proxy-addr is for, which i haven't had to implement. PR would be welcomed. #281 |
So getting the last ip of ctx.ips is not enough? |
This seems to be working for returning the real ip:
|
the client's ip should be first, check out https://en.wikipedia.org/wiki/X-Forwarded-For |
I know, I want the last ip because it is returning LAN ips |
There's a problem using koa over nginx server, when I force X-Forwarded-For in the request. An Found the problem in line 381 of koa/lib/request.js It's better use X-Real-IP over X-Forwarded-For. |
|
Thats because NginX appends external request's |
hmm yea I suppose it depends how nginx is configured, though if you have X-Real-IP you might as well just clobber X-Forwarded-For to ensure it's correct and not spoofed |
If your koa app behind a nginx, you must add 'proxy_set_header X-Forwarded-For $remote_addr' to the nginx proxy conf. |
I just found that you can spoof an IP address on the standard configuration of nginx. And I happen to whitelist payment servers on my webhook by an IP address. |
in nginx: in node koa: |
for me this worked plus
|
I had the same problem but resolved it by using this module found on NPM in koa it can be simply used The user ip is determined by the following order:
If an IP address cannot be found, it will return null. |
I set
app.proxy = true
but sometimes I still get someone withctx.ip = "127.0.0.x"
The text was updated successfully, but these errors were encountered: