一、SLB后Nginx如何获取真实IP

前提:nginx作为slb获取真实ip是使用 http_realip_module,默认一键安装包安装的nginx没有安装这个模块需要重新重新编译nginx并加装。

  查看是否安装此模块:./nginx -V

  如没有安装此模块,需重新编译nginx增加 --with-http_realip_module

1、阿里云SLB需要开启获取真实IP(默认已开启)

2、修改Nginx配置文件nginx.conf

添加:

http {

  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  /home/logs/nginx_access.log  main;

  server {
    listen 80;
    server_name domain_name;
    location / {
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://IPADDR:PORT;
    }
  }

}

3、日志内容如下:

二、SLB后Tomcat如何获取真实IP

1、修改Tomcat配置文件

   

2、重启Tomcat服务,日志内容如下:

阿里云SLB后Nginx、Tomcat获取真实IP的更多相关文章

  1. nginx代理tomcat后,tomcat获取真实(非proxy,非别名)nginx服务端ip端口的解决方案

    nginx代理tomcat后,tomcat获取服务端ip端口的解决方案 1.注意修改nginx配置代理,标红地方 #user nginx; worker_processes ; error_log l ...

  2. 记阿里云SLB后配置Nginx反向代理百度地图API的坑

    需求: 百度的原始请求:https://api.map.baidu.com/place/v2/suggestion?query=s&region=sc&city_limit=true& ...

  3. 【 Tomcat 】后端tomcat获取真实IP

    环境: nginx + tomcat nginx.conf 配置: proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_ad ...

  4. nginx后的tomcat获取真实用户ip

    目前大部分获取ip的方式:beat.getRequest().getRemoteAddr()但是,如果通过nginx反向代理的话,就获取不到真实ip,是获取的nginx的ip 需要:添加    pro ...

  5. nginx中获取真实ip(转)

    原文:http://blog.csdn.net/a936676463/article/details/8961504 server { listen       80; server_name  lo ...

  6. nginx中获取真实ip

    nginx反向代理配置时,一般会添加下面的配置: proxy_set_header Host $host;      proxy_set_header X-Real-IP $remote_addr;  ...

  7. Nginx中获取真实ip地址

    location / { proxy_pass http://localhost; proxy_set_header Host $host; proxy_set_header X-Real-IP $r ...

  8. Nginx 获取真实 IP 方案

    问题根源: 基于七层的负载均衡系统,获取IP的原理都是通过XRI和XFF进行处理,从中选出“正常情况下”的源头IP,然而这两个Header都是普通的HTTP头,任何代理程序都可以轻易修改伪造它们,使得 ...

  9. 13.多级代理下Nginx透传真实IP

    1.基于代理(七层负载均衡)情况下 透传客户端的真实IP 环境: 10.0.0.5 proxy_node1 一级代理 10.0.0.6 proxy_node2 二级代理 10.0.0.7 proxy_ ...

随机推荐

  1. openssl生成ssl证书

    openssl生成ssl证书 x509证书一般会用到三类文,key,csr,crt. Key 是私用密钥openssl格,通常是rsa算法. Csr 是证书请求文件,用于申请证书.在制作csr文件的时 ...

  2. boost asio tcp server 拆分

    从官方给出的示例中对于 boost::asio::ip::tcp::acceptor 类的使用,是直接使用构造函数进行构造对象,这一种方法用来学习是一个不错的方式. 但是要用它来做项目却是不能够满足我 ...

  3. 一键配置openvpn

    页面:https://github.com/Nyr/openvpn-install openvpn-install OpenVPN road warrior installer for Debian, ...

  4. mvc ajax csrf

    http://www.cnblogs.com/zhyp/p/5556980.html http://www.asp.net/web-api/overview/security/preventing-c ...

  5. Ubuntu12.04解决gedit中文乱码问题

    Ubuntu12.04,终端中分别输入下面两条指令: gsettings set org.gnome.gedit.preferences.encodings auto-detected “['GB18 ...

  6. Ibatis.net总是报:【ExecuteStoreCommand SqlParameterCollection 中已包含 SqlParameter】(转)

    今天很奇怪调用EF的ExecuteStoreCommand 出现了个这样的错误,怎么也调试不过,痛定思痛 原来 command被连着调用了而没有销毁掉   public static DataTabl ...

  7. Javascript中判断变量是 array还是object(是数组还是对象)

    段文字是从github上截取由本人翻译过来的. 原文地址:https://github.com/nathansmith/javascript-quiz/blob/master/ANSWERS.md 怎 ...

  8. php使用mysql和mysqli连接查询数据

    mysql: <?php $code = $_POST['code']; $status = ""; $success = ""; $scookies = ...

  9. AX7: Quick and easy debugging

    This purpose of this blog is to show how you can get quickly get started with debuggingin AX7, speci ...

  10. C# .NET 基本概念

    1. private. protected. public. internal 修饰符的访问权限.   private : 私有成员, 在类的内部才可以访问.    protected : 保护成员, ...