Using Nginx reverse proxy, how the backend Web obtains real customer IP

Source: Internet
Author: User
Tags nginx server nginx reverse proxy

Using Nginx reverse proxy, how the backend Web obtains real client IP


One, Nginx reverse proxy nginx, the back end of Nginx How to configure to get to the client's real IP address it.

1. First, you need to add a row of parameters to the location on the configuration file nginx.conf on the Nginx Proxy server:

Proxy_set_header X-real-ip $remote _addr;
Restart Nginx Service


2. Configure the rear Nginx

vim/usr/local/nginx/conf/nginx.conf Add the following parameters:

Set_real_ip_from 192.168.88.133; #ip为nginx代理服务器的ip地址, this line needs to be added to HTTP, but outside the server

Restart Nginx Service

The above configuration will be able to view the client's real IP address on the back-end Nginx server.


Second, Nginx reverse proxy Apache

1. On the proxy server Nginx configuration and reverse proxy nginx configuration is the same, reference 1-1, here will not repeat;

2. Configure Apache

Vim/usr/local/apache2/conf/httpd.conf Find the following

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

Modify the '%h' in this line to '%{x-real-ip}i'

Restart Nginx service can be;

The above configuration will be able to view the real client IP address on the back-end Apache.

This article from the "Shallow faint" blog, reproduced please contact the author!

Using Nginx reverse proxy, how the backend Web obtains real customer 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.