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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM