惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Security Latest
Security Latest
C
Cisco Blogs
P
Palo Alto Networks Blog
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
C
Cyber Attacks, Cyber Crime and Cyber Security
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
D
Docker
Google Online Security Blog
Google Online Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Recent Announcements
Recent Announcements
T
The Exploit Database - CXSecurity.com
G
Google Developers Blog
Schneier on Security
Schneier on Security
小众软件
小众软件
爱范儿
爱范儿
GbyAI
GbyAI
J
Java Code Geeks
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
The Hacker News
The Hacker News
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
TaoSecurity Blog
TaoSecurity Blog
MyScale Blog
MyScale Blog
B
Blog RSS Feed
Cyberwarzone
Cyberwarzone
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Securelist
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Y
Y Combinator Blog
S
Schneier on Security
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
F
Fortinet All Blogs
M
MIT News - Artificial intelligence
PCI Perspectives
PCI Perspectives
V
V2EX
V2EX - 技术
V2EX - 技术
O
OpenAI News
W
WeLiveSecurity

kekxv 技术日志

基于 kekxv/gitea-pages 与 Gitea Actions 构建静态站点托管服务 Json简单工具 在Windows上运行Code Server:结合WSL打造你的云端VS Code开发环境 安卓sdkmanager工具换源 boost bazel starter bazel 供应商模式 PVE引导丢失修复 NSFW图像检测 警惕c++内置变量指针 关于内网springboot启动慢记录 网页转换为chrome插件 YOLOv8 训练自己的数据 luckfox-交叉编译之bazel gitea actions CICD 自动化 Linux限制进程使用率 影音中心Jellyfin快速部署 OCR & 人脸算法 -- opencv dnn tensorflow gpu 安装(ubuntu22.04) 深度学习记录-简单
nginx代理的一种使用方式
kekxv · 2024-02-27 · via kekxv 技术日志

nginx 的代理相信大家都使用过,例如负载均衡,高可用等等,对于这些应用,资料有很多,但是像是以下这种很特别的情况,却没啥资料:

GET http://www.example.com/http://file.example.com/download.bin

只能访问www.example.com,但是想要使用file.example.com的文件,其中file.example.com是动态的;这种情况下,简单的方式是,在服务器上配置子路径,进行一一对应,可如果file.example.com有很多呢?

本文仅作为一个记录。

当前方法不适合直接暴露在公网,可能会导致意料之外的安全问题。如果确实想要在公网使用,请配置防火墙,或者访问白名单

配置IP白名单的时候,请考虑docker等容器导致内网IP影响

配置的方式通过nginx的正则方式,因为在一些浏览器里面 // 会变为单个/进行请求,所以代码里面加上?表达式,可选其中一个/

为了能够将GET参数传递,去掉了表达式的结尾$,同时在 proxy_pass 后加上$is_args$args

同样,为了兼容httphttpshttps里面的s使用(s?)进行提取,有需要的话,可以考虑加上ftp但是目前已经没啥服务会使用ftp协议直接传输

最后的配置内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
geo $ip_list {
default 0;
#设置默认值为0
127.0.0.1 1;
#172.21.0.1 1;
}
server {
....

location ~ ^/http(s?)://?(.*) {
# 此处 = 0 则是白名单访问;即只有列出来的IP能访问
# 此处 = 1 则是黑名单访问;即除了列出来的IP,都能访问
if ( $ip_list = 0 ) {
return 403;
}
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http$1://$2$is_args$args;
}

....
}