Egg.js 获取真实 IP

realIp() {
	let realIp = this.get('X-FORWARDED-FOR');
	realIp = realIp.split(',')[0];
	if (!realIp || realIp == '127.0.0.1') {
		realIp = this.get('x-real-ip');
	}
	if (!realIp) {
		realIp = this.request.ip;
	}
	return realIp;
}

你可能感兴趣的:(杂论,node.js)