首页 > 系统相关 >Nginx代理模式下 log-format 获取客户端真实IP

Nginx代理模式下 log-format 获取客户端真实IP

时间:2023-07-28 19:01:17浏览次数:36  
标签:web log format server access Nginx 10.43


一:环境描述

A:    windows client       10.43.2.213

B:    Nginx  proxy        10.43.2.11

C:    Nginx  web-server     10.43.2.54

其中,A,B,C三台主机,A是通过windows中的浏览器,B是Nginx代理服务器,C是用Nginx做的web服务器,访问web的流程如下:  A————>B————>C

二:修改Nginx web-server配置文件如下:







log_format 制定Log的记录格式。

如果不告诉web-server从哪里获取客户端的IP地址的话,web-server默认只能获得代理服务器的IP地址。

三:效果演示


在A上的浏览器访问: 

 

查看日志结果如下:/var/log/nginx/access.log  

 


server {
    listen       80;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        set_real_ip_from 10.43.2.11;
        real_ip_header X-Real-IP;
    }

标签:web,log,format,server,access,Nginx,10.43
From: https://blog.51cto.com/u_6186189/6886263

相关文章

  • GZIP file format …
    http://www.gzip.org/zlib/rfc-gzip.html#file-formatStatusofThisMemoThismemoprovidesinformationfortheInternetcommunity.ThismemodoesnotspecifyanInternetstandardofanykind.Distributionofthismemoisunlimited.IESGNote:TheIESGtake......
  • sublime配置Verilog环境
    官网下载sublime进入界面CTRL+shift+p,点击第一个,等待一会出现另一个搜索框输入ChineseLocalizations汉化输入verilog,选择出现的第一个即可视图--->语法----->verilog即可自动补齐......
  • linux nginx 安装
    一、nginx下载地址:http://nginx.org/en/download.html二、下载nginx对应的包   三、上传到对应的服务器四、解压安装##解压文件tar-zxvfnginx-1.22.0.tar.gz##重命名文件mvnginx-1.22.0nginx##nginx安装前配置信息./configure\--prefix=/usr/local/ngin......
  • linux nginx 简单负载均衡 和多端口配置
    nginx负载均衡配置##Nginx需要访问linux文件系统,必须有文件系统的权限。Userroot代表nginx访问文件系统的权限是root用户权限。如果不开启权限,可能有404访问错误userroot;worker_processes1;events{worker_connections1024;}http{includem......
  • Windows环境下安装及部署Nginx
    一、安装Nginx教程1、官网下载地址:https://nginx.org/en/download.html2、下载教程:选择Stable version版本下载到本地3、下载完成后,解压放入本地非中文的文件夹中:4、启动nginx:双击nginx.exe,若双击未弹出内容,则说明端口被占用,请参照第6步 或者使用命令行:输入start nginx......
  • nginx的keepalive_requests参数
    在Nginx中,keepalive_requests指令用于控制与客户端和代理服务器之间keep-alive连接的请求次数。在HTTP配置中,它控制Nginx与客户端之间keep-alive连接的请求次数。在upstream配置中,它控制Nginx与上游服务器之间keep-alive连接的请求次数。以下是两种keepalive_r......
  • nginx 负载均衡
    nginx配置:worker_processes1;events{worker_connections1024;}http{server{listen8081;location/{root/data/xc1;}}server{listen8082;location/{root/data/xc2;}}server{list......
  • 筛选出 1指定行( 编号中包含login的行),2指定列的值 放到列表中
    第一版 写死了列的值的下标,不够人性化,还需要去数列在第几个位置#导包importxlrd#第一步根据包提供的方法读某个路径下的xlsworkbook=xlrd.open_workbook('../data/testcase.xls')#第二步根据名字找某个表每个excel里有Sheet1Sheet2等worksheet=wor......
  • nginx for Windows
    配置nginx.confworker_processes1;events{worker_connections1024;}http{server{listen8092;server_namelocalhost;location/{rootD:/IdeaProjects/xcProjects/test/RuoYi-Vue/ruoyi-ui/dist;try_files$uri......
  • nginx 代理服务
     nginx.confworker_processes1;events{worker_connections1024;}http{server{listen8080;root/data/up1;location/{}}server{location/{proxy_passhttp://localhost:8080;}location/www{......