nginx负载均衡后端RS中获取真实ip

前端proxy配置

####################

worker_processes  1;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

upstream backend {

server 10.0.0.3:80    max_fails=3 fail_timeout=30s;

server 10.0.0.4:80    max_fails=3 fail_timeout=30s;

}

server {

listen       80;

server_name  www.lvnian.com lvnian.com;

location / {

root   html;

index  index.html index.htm;

proxy_pass http://backend;

proxy_redirect              off;

proxy_set_header            Host $host;

proxy_set_header            X-real-ip $remote_addr;

proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;

##上面四个是记录真实IP,以及可以区分后端不同业务的配置

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

#####################################

server {

listen       80;

server_name  bbs.lvnian.com lvnian.com;

location / {

root   html;

index  index.html index.htm;

proxy_pass http://backend;

proxy_redirect              off;

proxy_set_header            Host $host;

proxy_set_header            X-real-ip $remote_addr;

proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;

##上面四个是记录真实IP,以及可以区分后端不同业务的配置

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

}

##################################################

后端RS配置

##################################################

##################################################

worker_processes  1;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

server {

listen       80;

server_name  www.lvnian.com;

location / {

root   html;

index  index.html index.htm;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

#########

set_real_ip_from   10.0.0.0/24;

real_ip_header X-Forwarded-For;

######这两个参数是记录真实IP的

}

###########

server {

listen       80;

server_name  bbs.lvnian.com;

location / {

root   bbs;

index  index.html index.htm;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

#########

set_real_ip_from   10.0.0.0/24;

real_ip_header X-Forwarded-For;

######这两个参数是记录真实IP的

}

}

##################################################

##################################################

注意:

RS的日志格式中也需要指定记录客户端IP才可以。

##################################################

如果后端RS添加记录真实的IP之后,语法检查无法通过,可能是--with-http_realip_module 模块没有安装。

在已经安装的nginx服务上门,添加nginx模块方法如下

##添加新模块

1.查看nginx编译安装时的命令,安装了哪些模块

/application/nginx/sbin/nginx -V

2.加入需要安装的模块,重新编译

pkill nginx

cd /home/lvnian/tools/nginx-1.6.2

./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.2 --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module

make

make就可以了,但是不要make install,否则会覆盖

make

3. 替换nginx二进制文件:

cp /app/nginx/sbin/nginx /app/nginx/sbin/nginx.bak

cp ./objs/nginx /app/nginx/sbin/

4.启动nginx

/application/nginx/sbin/nginx -V

/application/nginx/sbin/nginx -t

/application/nginx/sbin/nginx

#######################################################

pkill nginx

cd /home/lvnian/tools/nginx-1.6.2

./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.2 --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module

make

cp /application/nginx/sbin/nginx /application/nginx/sbin/nginx.bak

cp objs/nginx /application/nginx/sbin/nginx

/application/nginx/sbin/nginx -V

/application/nginx/sbin/nginx -t

php负载均衡如何获得真实ip,nginx负载均衡后端RS中获取真实ip相关推荐

  1. 如何在PHP中获取客户端IP地址[重复]

    本文翻译自:How to get the client IP address in PHP [duplicate] This question already has an answer here: ...

  2. vue中获取本地IP地址

    vue中获取本地IP地址 IP地址需要通过js获取: 网上有很多查询接口可以获取到IP,查到的搜狐的比较多,我这里就用搜狐的: http://pv.sohu.com/cityjson?ie=utf-8 ...

  3. 从HTTP请求中获取客户IP地址

    /*** 从HTTP请求中获取客户IP地址** @param request http请求* @return 客户IP地址*/public static String getIPAddress( Ht ...

  4. nginx反向代理后,java获取真实ip和解决request.getServerName()的问题

    1. nginx.conf的server下增加以下配置 #解决request.getServerName()的问题proxy_set_header Host $host:$server_port;pr ...

  5. 使用nginx后如何在web应用中获取用户ip及原理解释

    http://www.iteye.com/topic/1124492 问题背景: 在实际应用中,我们可能需要获取用户的ip地址,比如做异地登陆的判断,或者统计ip访问次数等,通常情况下我们使用requ ...

  6. java项目中获取真实ip地址

    一.工具类 /*** 获取客户端IP** @param request 请求对象* @return IP地址*/public static String getIpAddr(HttpServletRe ...

  7. 如何在 ASP.NET CORE 中获取客户端 IP ?

    咨询区 eadam: 在 ASP.NET 中我可以用 Request.ServerVariables["REMOTE_ADDR"] 来获取客户端IP地址,请问在 ASP.NET C ...

  8. c#中获取服务器IP,客户端IP以及Request.ServerVariables详细说明

    客户端ip: Request.ServerVariables.Get("Remote_Addr").ToString();  客户端主机名: Request.ServerVaria ...

  9. java中获取网络ip

    平常项目中我们需要在日志记录中记录当前登录人的ip等信息,因此,下面列出一个公共的获取本地ip的方法. import javax.servlet.http.HttpServletRequest; pu ...

最新文章

  1. Keil uVision5中配置stm32标准固件库v3.5
  2. SAP 物料订单创建、下达、报工、收货与投料(ABAP代码)
  3. Linux下c开发 之 线程通信与pthread_cond_wait()的使用
  4. ubuntu 手动安装mysql
  5. c++中射线表示_射线与球的相交测试
  6. html清除div浮动,HTML_清除浮动的最优方法:CSS,在CSS森林群里讨论一个margin的 - phpStudy...
  7. 【NetApp】可以使用查设备备件型号的链接
  8. Q73:蒙特•卡罗积分(Monte Carlo Integration)
  9. 改变世界的十大计算机病毒(图)
  10. nRF52840(一) 环境搭建
  11. mySQL数据库学习的一些心得
  12. 计算机硬盘的存储时间,存储访问时间
  13. AI一分钟 | 美媒称中国导弹阵地遭美国AI技术快速识别,人工智能主播将亮相BBC节目
  14. Ubuntu赋予root权限
  15. 订单用户表2(用户名查询、手机号查询、选择城市、选择状态、选择月份、ID排序、添加数据、批量发货、批量删除、敏感字、修改数据)
  16. wps2022无法加载此加载项程序mathpage.wll
  17. 剑网三查询服务器角色信息,剑网三人物介绍
  18. 04 ARM Mali-V VPU硬件视频编解码驱动介绍V61
  19. Android实现视频播放的3种实现方式
  20. ‘C:\Users\Administrator\Desktop\gitSpace\dj-2\dj\vue-manager-dj\node_modules\node-sass\vendor‘

热门文章

  1. 面对 MySQL 查询索引失效,程序员的六大优化技巧!
  2. 以太坊新生合约总数骤减;比特币大跌,本周主链排名震荡 | 数据周榜
  3. 如何快速教妹子学Python?这个方法火了!
  4. 取代不了 C/C++ 的 Rust 如何“逆袭”?
  5. 苹果:失了 5G 会何妨?
  6. 腾讯掌舵者马化腾,才是移动互联网的大功臣?
  7. 短视频就这样玩丢了底线
  8. 我热爱编程,但我讨厌这个行业
  9. 苹果收购Siri的八年,是成还是败?
  10. 苹果发布 iOS、macOS 更新,系统修复英特尔重大漏洞