Haproxy forwarding real IP to the Web

Source: Internet
Author: User
Tags haproxy

1. Add the following parameters to the haproxy.cfg.

Option Forwardfor #如果后端服务器需要获得客户端真实ip需要配置的参数, must be placed under the Listen module

2. If it is Apache, add the following parameter (i.e. modify)

Logformat "\"%{x-forwarded-for}i\ "%l%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined is mainly "\"%{ X-forwarded-for}i\ This parameter can record IP

Here we can write so conveniently cut logs Logformat "%{x-forwarded-for}i%l%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" Combined note space Class, can be copied directly

3. If the backend web is Nginx, add the following parameters

Set_real_ip_from IP, (this IP is filled with proxy IP)

Real_ip_header x-forwarded-for;

Log_format Main ' $remote _addr– $remote _user [$time _local] "$request" '

' $status $body _bytes_sent ' $http _referer '

' "$http _user_agent" "$http _x_forwarded_for" '

============================================= (The following log path is also defined as main and Apache, which belongs to a log format)

Add $remote_addr or $http_x_forwarded_for parameters to the Log_format.

Haproxy forwarding real IP to the Web

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.