node.js - get ip user with nginx and node -


i have problem nginx , node, because when want ip of user node, in localhost works ok(no use nginx) in server dont work should. researching , see node no first receive ip, nginx , after nginx send request node. ip node receive server , not user's ip. the configuration server nignx:

location / {         proxy_pass https://fotogena.co:8000;  <-nginx send req node         proxy_http_version 1.1;         proxy_set_header upgrade $http_upgrade;         proxy_set_header connection "upgrade";         proxy_set_header host $host;         proxy_connect_timeout   1000;         proxy_send_timeout      1500;         proxy_read_timeout      2000; } 

i use "req.connection.remoteaddress" know ip of user , console show me ip of server. know how solve problem?

thanks :d

-----------2016-04-20--------

i can solved problem, line on nginx file setting

proxy_set_header x-real-ip $remote_addr; 

and node.js

req.headers['x-forwarded-for'] 

you can configure nginx pass client's ip address following setting:

location / {         proxy_pass https://fotogena.co:8000;         proxy_http_version 1.1;         proxy_set_header upgrade $http_upgrade;         proxy_set_header connection "upgrade";         proxy_set_header host $host;         proxy_set_header x-real-ip $remote_addr;  # line.         proxy_connect_timeout   1000;         proxy_send_timeout      1500;         proxy_read_timeout      2000; } 

you can use http header x-real-ip req.headers["x-real-ip"].


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -