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

推荐订阅源

Martin Fowler
Martin Fowler
L
LINUX DO - 最新话题
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
L
LINUX DO - 热门话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
V
Visual Studio Blog
O
OpenAI News
AI
AI
Hacker News: Ask HN
Hacker News: Ask HN
V2EX - 技术
V2EX - 技术
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
Spread Privacy
Spread Privacy
Y
Y Combinator Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
T
The Blog of Author Tim Ferriss
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
N
News and Events Feed by Topic
Project Zero
Project Zero
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog
G
Google Developers Blog

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;
}

....
}