牛下载:绿色软件官方软件免费下载基地!
所在位置:首页 > 新闻资讯 > 配置haproxy在http请求头添加后端用户真实IP

配置haproxy在http请求头添加后端用户真实IP

发布时间:2020-07-05 15:35:34来源:阅读:

在haproxy的配置文件中的前端bind下添加如下配置:

http-request set-header ZXTMIP %[src]

ps:其中ZXTMIP是自定义的字段 %[src]是取得IP

测试结果:

spacer.gif在浏览器中打开测试域名后的输出如下:

Array ( [TEMP] => /var/tmp [TMPDIR] => /var/tmp [TMP] => /var/tmp [PATH] => /usr/local/bin:/usr/bin:/bin [HOSTNAME] => mptest.okooo.com [USER] => web [HOME] => /var/webroot [FCGI_ROLE] => RESPONDER [SCRIPT_FILENAME] => /home/oae/web/wwwroot/public/index.php [QUERY_STRING] => [REQUEST_METHOD] => GET [CONTENT_TYPE] => [CONTENT_LENGTH] => [SCRIPT_NAME] => /index.php [REQUEST_URI] => / [DOCUMENT_URI] => /index.php [DOCUMENT_ROOT] => /home/oae/web/wwwroot/public [SERVER_PROTOCOL] => HTTP/1.1 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_SOFTWARE] => nginx/1.6.2 [REMOTE_ADDR] => 192.168.1.231 [REMOTE_PORT] => 6824 [SERVER_ADDR] => 192.168.1.235 [SERVER_PORT] => 80 [SERVER_NAME] => mptest.okooo.com [REDIRECT_STATUS] => 200 [HTTP_HOST] => mptest.okooo.com [HTTP_UPGRADE_INSECURE_REQUESTS] => 1 [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8 [HTTP_COOKIE] => LastUrl=; __utma=56961525.524112254.1501123742.1501123742.1501123742.1; __utmz=56961525.1501123742.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) [HTTP_ZXTMIP] => 111.200.213.110 [HTTP_X_FORWARDED_FOR] => 111.200.213.110 [HTTP_CONNECTION] => close [PHP_SELF] => /index.php [REQUEST_TIME_FLOAT] => 1501644453.5864 [REQUEST_TIME] => 1501644453 )
反对
收藏
  • 热门资讯
  • 最新资讯
  • 应用排行榜
  • 游戏排行榜