当前位置:网站首页>实现反向代理客户端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地址透传。
边栏推荐
- audiopolicy
- Business introduction of Zhengda international futures company
- Distance from point to line intersection and included angle of line
- C language - structural basis
- Exponential weighted average and its deviation elimination
- Ieventsystemhandler event interface
- Why does the C# compiler allow an explicit cast between IEnumerable< T> and TAlmostAnything?
- Double pointeur de liste liée (pointeur rapide et lent, pointeur séquentiel, pointeur de tête et de queue)
- Google Maps case
- 鏈錶之雙指針(快慢指針,先後指針,首尾指針)
猜你喜欢
Metaverse Ape获Negentropy Capital种子轮融资350万美元
How can easycvr cluster deployment solve the massive video access and concurrency requirements in the project?
Masked Autoencoders Are Scalable Vision Learners (MAE)
关于MySQL的30条优化技巧,超实用
d3dx9_ What if 29.dll is missing? System missing d3dx9_ Solution of 29.dll file
Google Maps case
2022软件测试工程师涨薪攻略,3年如何达到30K
航海日答题小程序之航海知识竞赛初赛
链表之双指针(快慢指针,先后指针,首尾指针)
2022.02.13 - SX10-30. Home raiding II
随机推荐
Navigation day answer applet: preliminary competition of navigation knowledge competition
The code generator has deoptimised the styling of xx/typescript.js as it exceeds the max of 500kb
Request preview display of binary data and Base64 format data
实战:fabric 用户证书吊销操作流程
Double pointer of linked list (fast and slow pointer, sequential pointer, head and tail pointer)
Record several frequently asked questions (202207)
I closed the open source project alinesno cloud service
Masked Autoencoders Are Scalable Vision Learners (MAE)
Distributed solution selection
700. Search in a Binary Search Tree. Sol
终于搞懂什么是动态规划的
Global and Chinese markets of tantalum heat exchangers 2022-2028: Research Report on technology, participants, trends, market size and share
Metaverse Ape获Negentropy Capital种子轮融资350万美元
513. Find the value in the lower left corner of the tree
VOT Toolkit环境配置与使用
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
Spectrum analysis of ADC sampling sequence based on stm32
The countdown to the launch of metaverse ape is hot
Lesson 1: serpentine matrix
fibonacci search