当前位置:网站首页>实现反向代理客户端IP透传
实现反向代理客户端IP透传
2022-07-05 22:44:00 【wwzroom】
实验环境:
1.修改nginx代理配置文件
[[email protected]:/apps/nginx/conf.d]#
vim pc.conf
server {
listen 80;
proxy_cache off;
#proxy_cache proxycache;
#proxy_cache_key $request_uri;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 302 301 10m;
proxy_cache_valid any 5m;
add_header class M44;
add_header X-Via $server_addr;
add_header X-Cache $upstream_cache_status;
add_header X-Accel $server_name;
proxy_hide_header ETag;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #添加客户端IP和反向代理服务器IP到请求报文头部
#listen 443 ssl;
#ssl_certificate /apps/nginx/conf.d/ssl/www.magedu.org.crt;
#ssl_certificate_key /apps/nginx/conf.d/ssl/www.magedu.org.key;
#ssl_session_cache shared:sslcache:20m;
#ssl_session_timeout 10m;
server_name www.magedu.org;
root /data/nginx/html/pc/;
location / {
root /data/nginx/html/pc/;
}
location /api {
proxy_pass http://10.0.0.8:8080/;
}
location ~* \.(jpe?g|png|bmp|gif)$ {
#实现反向代理
proxy_pass http://10.0.0.28;
}
}
[[email protected]:/apps/nginx/conf.d]#
nginx -s reload
2.后端服务器日志中添加查看头部的规则。添加\"%{
X-Real-IP}i\"
[[email protected]:~]#
vim /etc/httpd/conf/httpd.conf
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-forwarded-for}i\" " combined
[[email protected]:~]#
systemctl restart httpd
3.客户端进行测试
[[email protected] ~]#curl www.magedu.org/16m.jpg -I
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 03 Jul 2022 01:50:18 GMT
Content-Type: image/jpeg
Content-Length: 16422438
Connection: keep-alive
Last-Modified: Sat, 02 Jul 2022 07:16:41 GMT
Accept-Ranges: bytes
class: M44
X-Via: 10.0.0.58
X-Accel: www.magedu.org
4.web服务器产看日志
[[email protected]:~]#
tail -f /var/log/httpd/access_log
10.0.0.58 - - [03/Jul/2022:09:54:23 +0800] "HEAD /16m.jpg HTTP/1.0" 200 - "-" "curl/7.58.0" "10.0.0.100"
#实现ip地址透传。
边栏推荐
- 【Note17】PECI(Platform Environment Control Interface)
- First, redis summarizes the installation types
- EasyCVR集群部署如何解决项目中的海量视频接入与大并发需求?
- Unity Max and min constraint adjustment
- Roman numeral to integer
- Tiktok__ ac_ signature
- 90后测试员:“入职阿里,这一次,我决定不在跳槽了”
- 700. Search in a Binary Search Tree. Sol
- Go language learning tutorial (XV)
- 2022.02.13 - SX10-30. Home raiding II
猜你喜欢
All expansion and collapse of a-tree
Metaverse Ape获Negentropy Capital种子轮融资350万美元
[speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]
Double pointer of linked list (fast and slow pointer, sequential pointer, head and tail pointer)
Nangou Gili hard Kai font TTF Download with installation tutorial
Common model making instructions
Metaverse Ape上线倒计时,推荐活动火爆进行
Navigation day answer applet: preliminary competition of navigation knowledge competition
一文搞定class的微觀結構和指令
Usage Summary of scriptable object in unity
随机推荐
Editor extensions in unity
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
Post-90s tester: "after joining Ali, this time, I decided not to change jobs."
My experience and summary of the new Zhongtai model
Nangou Gili hard Kai font TTF Download with installation tutorial
[groovy] groovy dynamic language features (automatic type inference of function arguments in groovy | precautions for function dynamic parameters)
Nanjing: full use of electronic contracts for commercial housing sales
Shelved in TortoiseSVN- Shelve in TortoiseSVN?
Nacos 的安装与服务的注册
Ultrasonic sensor flash | LEGO eV3 Teaching
Exponential weighted average and its deviation elimination
Go语言学习教程(十五)
Evolution of APK reinforcement technology, APK reinforcement technology and shortcomings
航海日答题小程序之航海知识竞赛初赛
我把开源项目alinesno-cloud-service关闭了
Leetcode daily question 1189 The maximum number of "balloons" simple simulation questions~
Global and Chinese markets of tantalum heat exchangers 2022-2028: Research Report on technology, participants, trends, market size and share
How to reverse a string fromCharCode? - How to reverse String. fromCharCode?
Assign the output of a command to a variable [repeat] - assigning the output of a command to a variable [duplicate]
Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space