[英]Nginx: Use different backend based on value of argument
我們有一個用php編寫的舊應用程序,現在正在遷移到Java。 由於應用程序比較龐大,我們正在嘗試部分遷移功能。 記住這種情況,我需要根據查詢字符串參數的值在php-fpm后端和Java應用程序之間分配流量
例如,如果$ format =“ csv”,則使用fast-cgi並使用php處理請求;如果$ format =“ xml”,則使用proxy_pass指令連接到Java后端。
不幸的是,我發現在nginx上很難做到這一點。
我嘗試了以下
if ($args_format ="csv")
include php;
if ($args_format ="xml")
include proxy;
這里的php和proxy是包含proxy_pass和fast-cgi相關語句的文件
不幸的是,這引發了語法錯誤
然后我使用類似的方法創建地圖
map $args_output $provider {
default "proxy";
csv "php";
}
然后做了一個include $ provider;
這也失敗了,因為nginx似乎在開始時而不是在每個調用執行期間加載include。
關於如何以一種優雅的方式實現這一目標的任何建議。
變量名稱為$ arg_format http://nginx.org/en/docs/http/ngx_http_core_module.html#var_arg_
您必須在if語句后使用{}。 http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if
嘗試類似...
if ($arg_format ="csv") {
include php;
}
if ($arg_format ="xml") {
include proxy;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.