1. 程式人生 > >haproxy 在http頭部添加後端用戶真實IP

haproxy 在http頭部添加後端用戶真實IP

haproxy 取用戶真是ip

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

http-request set-header ZXTMIP %[src]

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

測試結果:

技術分享在瀏覽器中打開測試域名後的輸出如下:

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 )

本文出自 “Dr小白” 博客,請務必保留此出處http://1213503.blog.51cto.com/1203503/1952946

haproxy 在http頭部添加後端用戶真實IP