Solve Haproxy proxy nginx get client real IP problem

Source: Internet
Author: User
Tags haproxy

Issue background:

Before our company due to DDoS attacks caused by network exports, after understanding, traffic into the Amazon is no money, and unlimited traffic, in order to strengthen the protection of network attacks on the business impact, in the Amazon to deploy a set of Haproxy agent, the part of the business migration trial.

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/83/1F/wKioL1drZeyxEL5mAAA1K9OBwBc668.png-wh_500x0-wm_3 -wmp_4-s_1612962770.png "title=" Aws-lvs-nginx.png "alt=" Wkiol1drzeyxel5maaa1k9obwbc668.png-wh_50 "/>

In order to use Nginx to obtain the IP address of the client, configure option httpclose and option Forwardfor,nginx configuration Set_real_ip_from x.x.x.x in Haproxy, and Real_ip_ Header x-forwarded-for; (where x.x.x.x is the public IP address of Haproxy), observe that the log finds that remote_addr gets the IP address of haproxy.

Then we check the official documents of Haproxy

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/83/1F/wKioL1drbGGTeJhRAABktkXZRw8298.png-wh_500x0-wm_3 -wmp_4-s_2259427357.png "style=" Float:none; "title=" Haproxy-forward1.png "alt=" Wkiol1drbggtejhraabktkxzrw8298.png-wh_50 "/>

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/83/1F/wKiom1drbGKTB8KwAABJlveXLEg236.png-wh_500x0-wm_3 -wmp_4-s_2198325183.png "style=" Float:none; "title=" Haproxy-forward2.png "alt=" Wkiom1drbgktb8kwaabjlvexleg236.png-wh_50 "/>

Add in haproxy config file backend xxx

Option Forwardfor Header x.x.x.x

Re-add Haproxy configuration file, observe nginx Access log, finally can get the client real IP!

Resolve Haproxy proxy nginx get client real IP problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.