Nginx tutorial-obtain the real IP module-http_realip_module

Source: Internet
Author: User
Nginx tutorial-get real IP module-http_realip_module in this case, a website has a lot of static files, and the source of user access is China Netcom, China Telecom, China Tietong... and abroad. Www.2cto.com to speed up static files for users in different network operators... nginx tutorial-get real IP module-http_realip_module in this case, a website has a lot of static files, and the source of user access is China Netcom, China Telecom, China Tietong... the setting is also abroad. Www.2cto.com, in order to make users of different network operators collect static files at a good rate, the website deploys Squid in the points of these operators, then the Proxy is unified to the Nginx on the master site to form a distributed cache architecture. If this is the case, the Nginx logs on the master station or the IP address source obtained by the application will always be the Squid IP address in each data center. Instead of the user's real IP address. Apache can solve the problem through mod_rpaf mentioned above. Of course, powerful Nginx also has its own magic weapon. Nginx has a module http_realip_module that is not loaded by default during compilation, which is used to implement this function. However, many authors on the Internet have completely misunderstood this module and thought it was the proxy_set_header in the Proxy parameter. Www.2cto.com proxy_set_header is used to forward the IP head to the backend. this parameter is located in the proxy_module, rather than http_realip_module. many bloggers wrote the purpose of this module as "providing realip for backend applications" on the official Nginx wiki to describe this module. http://wiki.nginx.org/NginxHttpRealIpModule "It is useful if nginx works behind some proxy of L7 load balanver, and request come from local IP, but proxy add request header with client's IP. this module isn't built by default, enable it with the configure option "to put it simply, that is, Nginx's http_realip_module = Apache's mod_rpaf is used to accept the IP head information sent from the front end, from getting the real user IP address. The configuration method is quite simple, re-compile Nginx with -- with-http_realip_module parameters, such :. /configure -- prefix =/opt/nginx -- with-http_stub_status_module -- with-pcre = .. /pcre-6.6 -- with-http_realip_modulemakemake install how? Is the Nginx service running? Isn't it easy to restart? Simple: you can choose where your Nginx is installed and where it is re-compiled. directly make install will overwrite the original one. Then run Killall-s USR2 nginx to perform smooth upgrade. Edit Nginx. conf www.2cto.com inserts set_real_ip_from 192.168.1.0/24 in the location. it specifies the front-end IP address that can be sent from which the header can be a single IP address or IP segment set_real_ip_from 192.168.2.1; real_ip_header X-Real-IP; the corresponding IP head parameter. the default value is enough. The configuration is roughly the same as that of mod_rpaf! After the configuration is complete, run the Killall-s HUP nginx command to smoothly load the configuration. In this way, the Nginx module is loaded without interruption.
 
Related Article

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.