nginx - NGINX - 使用 sub_filter 更改代理传递位置块中的路径
问题描述
因此,我有一个 NGNIX 服务器,它从同一位置 (Akamai) 接收流量,并根据传入 URL 的路径将流量发送到不同的应用程序。
我已向 Akamai 添加了一个新来源,这意味着一些传入请求现在有了新路径。问题是我的应用程序需要路径是某个值。
当我与其他来源共享 Akamai 插槽时,我无法将具有相同路径的请求发送到两个不同的来源,因为插槽对将流量引导至哪个源服务器感到困惑。
所以我想做的是在将路径传递给应用程序之前更改路径。我不确定执行此操作的最佳方法,需要一些帮助。我应该使用重写、重定向还是 sub_filter?
我实际上已经尝试了所有这三个,但我在这个非常简单的任务中遗漏了一些东西。
location /incoming_path {
max_ranges 0;
proxy_set_header Accept-Encoding "";
proxy_pass https://\$upstream_application:9002;
proxy_ssl_server_name on;
proxy_ssl_certificate /etc/nginx/conf.d/server_cert.pem;
proxy_ssl_certificate_key /etc/nginx/conf.d/server_key.pem;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$proxy_protocol_addr;
sub_filter_types *;
sub_filter "https://\$proxy_host/incoming_path" "https://\$host/new_path"
sub_filter_once on;
}
真的很感激任何关于如何实现这一目标的想法/想法,在此先感谢。
解决方案
这看起来奏效了:
location /incoming_path {
max_ranges 0;
rewrite /incoming_path/(.*) /new_path/$1 break;
proxy_pass https://\$upstream_application:9002;
proxy_ssl_server_name on;
proxy_ssl_certificate /etc/nginx/conf.d/server_cert.pem;
proxy_ssl_certificate_key /etc/nginx/conf.d/server_key.pem;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$proxy_protocol_addr;
}
推荐阅读
- excel - Excel 数据翻译 - INDEX、MATCH、OFFSET?
- javascript - react native导航中header组件的调用函数
- qt - QWidget 多种样式无法正常工作
- excel - 尝试将记录集分配给数组时出现错误“BOF 或 EOF 为真......”
- .net - 是否可以在应用程序启动时强制 Serilog.Sink.File 启动一个新的日志文件?
- sql - DBMail到Outlook的vb6 vs SQL脚本,出了什么问题?
- php - 使用嵌套 for 循环显示数据
- c# - 在新桌面中启动进程
- html - 如何让我的背景处于固定位置?
- php - Laravel 进程组件安全问题?