nginx反向代理 查看源ip

源192.168.1.148    apache的html

代理192.168.1.142nginx

访问192.168.1.141web

 

配置代理142apache

Vi /etc/nginx/nginx.confapp

worker_processes  2;测试

events {网站

    worker_connections  1024;代理

}rest

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

相关文章
相关标签/搜索