最近我们在开发的某SLG游戏的某业务要做如下场景:
要求在全球各个区域访问离他最近的服务器节点:用户通过访问域名A,在服务器端解析用户来源,根据ip地址来源来转发到对应的最近的服务器节点。
由于我们之前的业务一些设计很难调整,所以我将通过nginx来进行做转发处理,本片文章我将使用nginx/apache做反向代理来识别访问用户的ip区域来做转发。
首先,准备好安装 nginx服务器:
1. yum search nginx-module 先查找是否有geoip模块
2.安装geoip模块:
yum install nginx-module-geoip*
3.安装geoip安装。
yum install geoip-devel
4.配置nginx.conf
添加模块
load_module /usr/lib64/nginx/modules/ngx_http_geoip_module.so;
配置数据源:geoip_country /usr/share/GeoIP/GeoIP.dat; fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
load_module /usr/lib64/nginx/modules/ngx_http_geoip_module.so;
events {
worker_connections 65535;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
geoip_country /usr/share/GeoIP/GeoIP.dat;
fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#'$geoip_country_name $geoip_region $geoip_city';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
5.在配置文件里加入如下信息:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
if ($geoip_country_code = CN) {
proxy_pass http://www.baidu.com;
}
if ($geoip_country_code !~ CN) {
proxy_pass http://www.sohu.com;
}
}
}
6.这样不通区域的用户就被转发到就近的服务器节点上了。
此方案是建基于TencentOS Tiny CH32V_EVB RISC-V开发套件。开发板是采用沁恒RISC-VMCUCH32V307VCT6芯片,CH32V305/7系列是基于沁恒自研RISC-V架构微处理器青稞V4系列设计的32位工业级互联型微控制器,配备了硬件堆栈区、快速中断入口,在标准RISC-V基础上大大提高了中断响应速度。加入单精度浮点指令集,扩充堆栈区,具有更高的运算性能。扩展串口UART数量到8组,定时器到10组,其中4组高级定时器。提供USB2.0高速接口(480Mbps)并内置了PHY收发器,而以太网MAC升级到千兆并集成了10M-PHY模块,并且板载有esp8266 WiFi模组,支持腾讯云固件,这样提供了强大多元化的网络传输能力。同时板载有1.54寸 IPS高清显示屏,支持240*240分辨率,可以即时反馈相关的数据信息。再结合TencentOS Tiny开源物联网操作系统简便快速的开发如虎添翼。配合腾讯云物联网开发平台IoT Explorer 和腾讯连连小程序能高效地开发出基于物联网应用技术的智能设备。