当前位置:网站首页>实现反向代理客户端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地址透传。
边栏推荐
- BFC block level formatting context
- Qtquick3d real time reflection
- 90后测试员:“入职阿里,这一次,我决定不在跳槽了”
- 谷歌地图案例
- Global and Chinese markets for reciprocating seal compressors 2022-2028: Research Report on technology, participants, trends, market size and share
- C language - structural basis
- Starting from 1.5, build a micro Service Framework -- log tracking traceid
- Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
- VIM tail head intercept file import
- Sparse array [matrix]
猜你喜欢
Ieventsystemhandler event interface
Paddy serving v0.9.0 heavy release multi machine multi card distributed reasoning framework
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
Arduino measures AC current
VOT toolkit environment configuration and use
VOT Toolkit环境配置与使用
一文搞定class的微观结构和指令
南京:全面启用商品房买卖电子合同
一文搞定垃圾回收器
Postman核心功能解析-参数化和测试报告
随机推荐
Overview of Fourier analysis
a-tree 树的全部展开和收起
Postman core function analysis - parameterization and test report
MoCo: Momentum Contrast for Unsupervised Visual Representation Learning
南京:全面启用商品房买卖电子合同
Global and Chinese market of water treatment technology 2022-2028: Research Report on technology, participants, trends, market size and share
First, redis summarizes the installation types
TCC of distributed solutions
Nail error code Encyclopedia
Depth first DFS and breadth first BFS -- traversing adjacency tables
一文搞定class的微觀結構和指令
Practice: fabric user certificate revocation operation process
一文搞定垃圾回收器
Metaverse Ape上线倒计时,推荐活动火爆进行
Ultrasonic sensor flash | LEGO eV3 Teaching
Lesson 1: serpentine matrix
抖音__ac_signature
分布式解决方案之TCC
Damn, window in ie open()
[groovy] groovy dynamic language features (automatic type inference of function arguments in groovy | precautions for function dynamic parameters)