nginx反向代理 查看源ip

源192.168.1.148    apache的

代理192.168.1.142

访问192.168.1.141

配置代理142

Vi /etc/nginx/nginx.conf

worker_processes  2;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen     80;

        server_name  _;

        location / {

             proxy_pass http://192.168.1.148:80;

             proxy_set_header X-Real-IP $remote_addr;

 }

    }

}

systemctl restart nginx.service

配置源148的日志

vi /etc/httpd/conf/httpd.conf

 196行左右

LogFormat "%{X-Real-IP}i %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined

LogFormat "%h %l %u %t "%r" %>s %b" common

systemctl restart httpd.service

测试访问142会看到148的网站

查看148日志会看到访问者是141

  

cat /var/log/httpd/access_log

*************************************************************************

 nginx

在148中

vi /etc/nginx/nginx.conf

location / {

            root   /web;

            index  index.html index.htm;

set_real_ip_from 192.168.1.0/24;

 proxy_set_header X-Real-IP $remote_addr;

        }

142中同上。。。

查看148

cat /usr/local/nginx/logs/access.log

原文地址:https://www.cnblogs.com/han1094/p/6381908.html