Nginx forwarding and backend server to obtain real client IP

Source: Internet
Author: User



For Nginx module Introduction can consult the Wiki:http://wiki.nginx.org/modules

Common modules: HTTP Core

Proxy

Rewrite

Upstream


principle:
Squid,varnish and Nginx, when doing reverse proxy, because to replace the client to access the server, so, when the request packet through the reverse proxy, the proxy server here this IP packet IP header has been modified, Finally, the backend Web server gets the header source IP address of the packet is the IP address of the proxy server, so that the back-end server program to give the IP statistics function does not make any sense, so in the agent or cluster must solve this problem, here, When I do a cluster or proxy with nginx how to leave the backend Web server (to be exact, delivery) the real IP address of the client.


First, the following configuration is required on the front-end Nginx:

Location/{
Proxy_pass http://192.168.100.100;
Proxy_set_hearder host $host;
Proxy_set_header x-real_ip $remoute _addr;
};


The configuration file on the Apache server on the backend 192.168.100.100 is modified as follows.

Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined

Switch

Logformat "%{x-real-ip}i%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined

Can.

This article is from the "Autumn Fairy tale" blog, please be sure to keep this source http://wushank.blog.51cto.com/3489095/1678370

Nginx forwarding and backend server to obtain real client IP

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.