un33k / node-ipware

Returns the real IP address of users in Node.js
MIT License
124 stars 17 forks source link

ip-ware always return 127.0.0.1 with some nginx configs #6

Closed pcolazurdo closed 8 years ago

pcolazurdo commented 8 years ago

I've found that the current config have some issues with nginx servers acting as reverse proxy. You may want to consider this change in the configuration of the IPWARE_HTTP_HEADER_PRECEDENCE_ORDER as default, which solves nginx use case and possibly others.

"IPWARE_HTTP_HEADER_PRECEDENCE_ORDER": [ "HTTP_X_FORWARDED_FOR", "HTTP_CLIENT_IP", "HTTP_X_REAL_IP", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_FORWARDED_FOR", "HTTP_FORWARDED", "HTTP_VIA", "X_FORWARDED_FOR", "REMOTE_ADDR", "HTTP-X-FORWARDED-FOR", "HTTP-CLIENT-IP", "HTTP-X-REAL-IP", "HTTP-X-FORWARDED", "HTTP-X-CLUSTER-CLIENT-IP", "HTTP-FORWARDED-FOR", "HTTP-FORWARDED", "HTTP-VIA", "X-CLIENT-IP", "X-REAL-IP", "X-FORWARDED", "X-CLUSTER-CLIENT-IP", "X-FORWARDED-FOR", "REMOTE-ADDR" ]

Hope it helps, Pablo

timbowhite commented 8 years ago

+1 experiencing the same thing w nginx reverse proxy

un33k commented 8 years ago

Which header did the trick for you?

ahwayakchih commented 8 years ago

Hi.

I had similar issue when using this module on OpenShift. Correct me if i'm wrong, but node.js passes headers in a-b-c form, not a_b_c, which is used by default by ipware. Maybe default should be changed to the form used by node.js?

On OpenShift i get x-client-ip and x-forwarded-for.

Thanks for ipware!

update: i couldn't find any conversions in node's lib, so maybe it simply passes header names as they are. Found this: http://stackoverflow.com/a/22856867 - so they really seem uncommon. I remember underscore-using headers from PHP, but never seen them in nodejs world.

un33k commented 8 years ago

ipware 0.0.8 can now support hyphenated header keys. So both x-client-ip and x-forwarded-for will be handled if supplied by your proxy server.

martonic commented 7 years ago

ipware 0.0.8 worked after I added this line to nginx.conf under proxy_pass

proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;

That's all I had to do, nothing else.