zoukankan      html  css  js  c++  java
  • 阿里云SLB后Nginx、Tomcat获取真实IP

    一、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服务,日志内容如下:

  • 相关阅读:
    HTTP协议一次上传多个文件的方法
    PHP中include和require的区别
    jenkins持续集成工具
    vue加强(第二天)
    VUE(第一天)
    mybatis的SQL映射(加强)
    easyPOI的上传和下载(导入和导出功能)
    shiro登录授权框架
    SpringDataJPA(ORM对象关系映射框架)
    SpringSpringMVCJPA集成
  • 原文地址:https://www.cnblogs.com/taoge007/p/6066803.html
Copyright © 2011-2022 走看看