The premise is that the "Get real IP" feature is turned on in the SLB setting.
If only need to get real IP in the program, so long as in the program to get the value of http_x_forwarded_for is basically OK, do not need the following operation.
The following operations can be implemented Nginx or Apache log records of the user real IP or in Apache, nginx prohibit certain IP users access.
Nginx
Nginx as SLB to get real IP is using Http_realip_module, the default one-click installation package installed Nginx not installed This module needs to recompile nginx and install.
Take one-click installation package as an example
Recompile nginx Add--with-http_realip_module
wget http://soft.phpwind.me/top/nginx-1.0.12.tar.gz
Tar zxvf nginx-1.0.12.tar.gz
CD nginx-1.0.12
./configure--user=www--group=www--prefix=/alidata/server/nginx--with-http_stub_status_module- Without-http-cache--with-http_ssl_module--with-http_realip_module
Make
Make install
KILL-USR2 ' Cat/alidata/server/nginx/logs/nginx.pid '
Kill-quit ' Cat/alidata/server/nginx/logs/nginx.pid.oldbin '
Modify Nginx.conf
Vi/alidata/server/nginx/conf/nginx.conf
In
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64k;
Fastcgi_buffers 4 64k;
Fastcgi_busy_buffers_size 128k;
Fastcgi_temp_file_write_size 128k;
Add below
Set_real_ip_from IP address (this IP address is not the first SLB provided by the public network IP, the specific IP number can look at the previous Nginx log, if there are more than one to write on. )
Set_real_ip_from IP address (this IP address is not the first SLB provided by the public network IP, the specific IP number can look at the previous Nginx log, if there are more than one to write on. )
Real_ip_header x-forwarded-for;
Restart Nginx
/alidata/server/nginx/sbin/nginx-s Reload
Apache
Install Apache's Third-party module "MOD_RPAF", official website: http://stderr.net/apache/rpaf/
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
Tar zxvf mod_rpaf-0.6.tar.gz
CD mod_rpaf-0.6
/alidata/server/httpd/bin/apxs-i-c-n mod_rpaf-2.0.so mod_rpaf-2.0.c
Modify Apache Configuration/alidata/server/httpd/conf/httpd.conf
Add at the end
LoadModule Rpaf_module modules/mod_rpaf-2.0.so
Rpafenable on
Rpafsethostname on
Rpafproxy_ips IP Address
Rpafheader x-forwarded-for
Rpafproxy_ips IP address (this IP address is not the first SLB provided by the public network IP, the specific IP how many can look at the Apache log, usually have 2 to write)
Restart Apache after add complete
/alidata/server/httpd/bin/apachectl restart
Specific cases
LoadModule Rpaf_module modules/mod_rpaf-2.0.so
Rpafenable on
Rpafsethostname on
Rpafproxy_ips 10.242.230.65 10.242.230.131
Rpafheader x-forwarded-for