当前位置:网站首页>实现反向代理客户端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地址透传。
边栏推荐
- [secretly kill little buddy pytorch20 days] - [Day2] - [example of picture data modeling process]
- 90后测试员:“入职阿里,这一次,我决定不在跳槽了”
- d3dx9_ How to repair 31.dll_ d3dx9_ 31. Solution to missing DLL
- Starting from 1.5, build a micro Service Framework -- log tracking traceid
- Double pointeur de liste liée (pointeur rapide et lent, pointeur séquentiel, pointeur de tête et de queue)
- FBO and RBO disappeared in webgpu
- 點到直線的距離直線的交點及夾角
- [speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]
- Global and Chinese market of diesel fire pump 2022-2028: Research Report on technology, participants, trends, market size and share
- Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem
猜你喜欢
My experience and summary of the new Zhongtai model
航海日答题小程序之航海知识竞赛初赛
How to quickly experience oneos
Leetcode weekly The 280 game of the week is still difficult for the special game of the week's beauty team ~ simple simulation + hash parity count + sorting simulation traversal
Leetcode daily question 1189 The maximum number of "balloons" simple simulation questions~
audiopolicy
Opencv judgment points are inside and outside the polygon
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
[speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]
Arduino measures AC current
随机推荐
Roman numeral to integer
Golang writes the opening chapter of selenium framework
How to reverse a string fromCharCode? - How to reverse String. fromCharCode?
First, redis summarizes the installation types
2022.02.13 - SX10-30. Home raiding II
Solve the problem of "no input file specified" when ThinkPHP starts
Binary tree (II) -- code implementation of heap
Google Maps case
70. Climbing Stairs. Sol
Global and Chinese markets of industrial pH meters 2022-2028: Research Report on technology, participants, trends, market size and share
[groovy] mop meta object protocol and meta programming (Introduction to groovyobject interface | introduction to metaclass | implementation of class methods using groovyobject invokemethod)
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
[digital signal denoising] improved wavelet modulus maxima digital signal denoising based on MATLAB [including Matlab source code 1710]
點到直線的距離直線的交點及夾角
Distance from point to line intersection and included angle of line
南京:全面启用商品房买卖电子合同
Starting from 1.5, build a micro Service Framework -- log tracking traceid
Metaverse Ape上线倒计时,推荐活动火爆进行
APK加固技术的演变,APK加固技术和不足之处
基于STM32的ADC采样序列频谱分析