开发者社区> 问答> 正文

ECS问题:游戏服务器如何获取真实ip地址

经常看到开发者朋友发帖子咨询在购买ECS服务器后如何获取真实ip地址的问题。
最近整理了下ECS的使用手册,找到了设置的方法,可以供大家参考:



一、Windows下的获取真实IP方式:
这里给大家介绍IIS6和IIS7的获取方式


《IIS6环境》    《 IIS7环境》


二、Apache下获取真实IP方式:



Windows 2003 Server + Apache 解决方案:
1、打开文件:\apache\conf\httpd.conf。
2、在文件中查找:”CustomLog”,找到如下配置块: 查看到当前使用的LogFormat为”combined”(如果实际启用的为其他日志格式,替换相应的格式定义即可)。
3、在文件中查找:”LogFormat”,找到如下配置块(combined格式定义):
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
将其修改为:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"  \"%{X-Forwarded-For}i\"" combined
4、保存并关闭文件\apache\conf\httpd.conf。
5、重启Apache服务。

Linux + Apache 解决方案:
1、打开文件:/etc/httpd/conf/httd.conf。
2、在文件中查找:”CustomLog”,找到如下配置块: 查看到当前使用的LogFormat为”combined” (如果实际启用的为其他日志格式,替换相应的格式定义即可)。
  
#
# For a single logfile with access, agent, and referer information
# (Combined Logfile Format), use the following directive:
#
CustomLog  logs/access_log combined
3、在文件中查找:”LogFormat”,找到如下配置块(combined格式定义):
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
将其修改为:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-Forwarded-For}i\" " combined
4、保存并关闭文件/etc/httpd/conf/httd.conf。
5、重启Apache服务。


三、Nginx日志中获取访客真实IP的解决方案
  
解决方案如下:
1、打开文件:/etc/nginx/nginx.conf。
2、在文件中查找:”CustomLog”,找到如下配置块:
server {
        listen   80; ## listen for ipv4
        listen   [::]:80 default ipv6only=on; ## listen for ipv6
        server_name  localhost;
        access_log  /var/log/nginx/localhost.access.log;
3、将access_log这一行替换为如下内容:
log_format main '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" "$http_x_forwarded_for"' ;
  access_log /var/log/nginx/localhost.access.log  main;
4、保存并关闭文件/etc/nginx/nginx.conf。
5、重启Nginx服务。


展开
收起
domen 2014-06-26 15:28:10 10906 0
1 条回答
写回答
取消 提交回答
  • ReECS问题:游戏服务器如何获取真实ip地址
    这个好。
    2014-11-06 14:57:43
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS快储存加密技术 立即下载