获取用户真实ip地址
var net = require(‘net’), server = net.createServer(function© { //此处创建一个tcp服务器,如何通过参数c来获取用户的真实ip地址 //通过c.remoteAddress每次都是127.0.0.1 }); ps:我使用了cluster,用了ngnix做了代理,求高人指点。
4 回复
nginx里配置 proxy_set_header X-Real-IP $remote_addr;
node 里通过取HEADER “X-Real-IP” 获取真实IP
如果多层代理 nginx里配置 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@shimonxin
map $http_upgrade $connection_upgrade {
default upgrade;
’’ close;
}
upstream websocket {
#ip_hash;
server 127.0.0.1:1219;
}
server
{
listen 80;
server_name chat.domain.dev;
location / {
proxy_pass http://websocket;
#proxy_connect_timeout 60;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
# 下面是关键
proxy_http_version 1.1;
#proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 这是配置webpysessoin丢失的问题
#fastcgi_param SCRIPT_NAME "";
}
}
都配置了,还是不行
@shimonxin 参数c没有header属性