First, Nginx reverse proxy configuration:
1, the Virtual host configuration
Copy Code code as follows:
Location/{
Try_files $uri @apache;
}
Location @apache {
Internal
Proxy_pass http://127.0.0.1:8080;
Include proxy.conf;
}
Location ~. *\. (PHP|PHP5)? $ {
Proxy_pass http://127.0.0.1:8080;
Include proxy.conf;
}
2. Agent Configuration
Copy Code code as follows:
Proxy_connect_timeout 300s; #请求连接后端服务器超时时间. That is, at the specified time, the backend must respond to the front-end handshake request.
Proxy_send_timeout 900; #后端数据回传时间. That is, at the specified time, the backend server must return all data to completion.
Proxy_read_timeout 900; #后端服务器响应时间. That is, the connection is successful, waiting in the back-end to wait for processing can not exceed the time.
Proxy_buffer_size 32k; #从后端服务器读取的头信息的缓冲区大小.
Proxy_buffers 4 64k; #从后端服务器读取的头信息的缓冲区数目和大小
Proxy_busy_buffers_size 128k #如果服务器繁忙, the size of the proxy_buffers can be applied
Proxy_temp_file_write_size 64k; #代理缓存临时文件大小
Proxy_max_temp_file_size 128m; #代理最大缓存临时文件大小
Proxy_redirect off;
Proxy_hide_header Vary;
Proxy_set_header accept-encoding ';
Proxy_set_header Referer $http _referer;
Proxy_set_header cookies $http _cookie;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Second, Apache access to real IP module
Get the real IP address Apache has 2 modules:
mod_rpaf:apache-2.2 support; Apache-2.4 not supported. A lot of online tutorials, and the official website link has expired
mod_remoteip:apache-2.4 self-contained module; Apache-2.2 support; recommended
A, using the MOD_RPAF module
1, installation
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
TAR-XZVF mod_rpaf-0.6.tar.gz
CD mod_rpaf-0.6/
/usr/local/apache/bin/apxs-i-c-n Mod_rpaf-2.0.slo mod_rpaf-2.0.c
2, add Apache configuration
Copy Code code as follows:
Vi/usr/local/apache/conf/httpd.conf
Include conf/extra/httpd-rpaf.conf
Vi/usr/local/apache/conf/extra/httpd-rpaf.conf
LoadModule Rpaf_module modules/mod_rpaf-2.0.so
Rpafenable on
Rpafsethostname on
Rpafproxy_ips 127.0.0.1 10.8.0.110 # Proxy Server IP address (remember to make the appropriate changes)
Rpafheader x-forwarded-for
Note: rpafproxy_ips after adding the IP address of the proxy server, a few fill in several
3. Test
Copy Code code as follows:
#/usr/local/apache/bin/apachectl-t
#/usr/local/apache/bin/apachectl Restart
# See if the log gets the real IP
B, using the Mod_remoteip module
1, Apache-2.2 under the configuration Mod_remoteip as follows:
1), Installation
Copy Code code as follows:
wget https://github.com/ttkzw/mod_remoteip-httpd22/raw/master/mod_remoteip.c
/usr/local/apache/bin/apxs-i-c-n mod_remoteip.so mod_remoteip.c
2), modify the configuration file:
Copy Code code as follows:
Vi/usr/local/apache/conf/httpd.conf
Include conf/extra/httpd-remoteip.conf
Vi/usr/local/apache/conf/extra/httpd-remoteip.conf
LoadModule Remoteip_module modules/mod_remoteip.so
Remoteipheader x-forwarded-for
Remoteipinternalproxy 127.0.0.1
3), test:
Copy Code code as follows:
#/usr/local/apache/bin/apachectl-t
#/usr/local/apache/bin/apachectl Restart
# Look at the log
2, Apache-2.4 configuration Mod_remoteip
Self-MOD_REMOTEIP module does not need to be installed, only need to modify log format
Copy Code code as follows:
Logformat "%h%a%l%u%t \%r\"%>s%b \ "%{referer}i\" \ "%{user-agent}i\" "combined
Logformat "%h%a%l%u%t \"%r\ "%>s%b" common
Logformat "%h%l%u%t \%r\"%>s%b \ "%{referer}i\" \ "%{user-agent}i\"%I%o "Combinedi
Add%a to the log format