主机 功能 192.168.8.122 Nginx 代理 10.10.200.176 Web Server
Nginx Web Server 依赖模块
./configure --with-http_realip_module
Nginx Web Server 配置
[ dev@hessian01 conf.d] $ cat test_proxy_pass.conf
server {
listen 12022 ;
server_name localhost;
set_real_ip_from 192.168 .8.122;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
location / {
root /home/dev/nginx_proxy_pass_test;
index index.html;
}
}
Nginx 代理配置
[ dev@testbmj ~] $ cat /etc/nginx/conf.d/default.conf | grep -A5 testProxyPass
location /testProxyPass {
proxy_pass http://10.10.200.176:12022/;
proxy_set_header host "$host " ;
proxy_set_header X-Real-IP "$remote_addr " ;
proxy_set_header X-Forwarded-For "$proxy_add_x_forwarded_for " ;
}
日志查看
[ dev@hessian01 log] $ cat access.log | sort -k 1 | uniq -w 20
10.10 .196.174 - - [ 31 /Aug/2021:00:33:10 +0800] "GET / HTTP/1.0" 200 21 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36"
10.10 .200.16 - - [ 31 /Aug/2021:00:33:21 +0800] "GET / HTTP/1.0" 200 21 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
10.10 .200.176 - - [ 31 /Aug/2021:00:08:03 +0800] "GET /index.html HTTP/1.1" 200 21 "-" "curl/7.29.0"
10.10 .200.77 - - [ 31 /Aug/2021:00:00:37 +0800] "GET /index.html HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Edg/92.0.902.78"
192.168 .8.122 - - [ 31 /Aug/2021:00:01:18 +0800] "GET / HTTP/1.0" 200 21 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Edg/92.0.902.78"
参考