我正在尝试将相对URL“ / A”重写为“ / B”,同时还设置了请求标头。 url / A已经公开给某些客户端。 / B本质上是/ A,其中Accept标头设置为“ json”。我正在尝试从上游删除/ A支持,而在上游只有/ B。但是我需要继续支持/ A。因此出现了问题
我能够成功重写,但是标题未设置。
int
以下内容对我有用,但是我看到nginx向自身发出了一个额外的请求,这并不是很酷。
Sub Format_step2_test()
Dim OldSheet As Worksheet
Set OldSheet = ActiveSheet
Sheets.Add(After:=ActiveSheet).Name = "Graphs"
ActiveWindow.View = xlPageLayoutView
With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False 'Will take as many pages as required based on other settings
End With
OldSheet.Activate
End Sub
有什么建议吗?
答案 0 :(得分:0)
location = /A {
set $accept "json";
rewrite /A /B;
}
location = /B {
proxy_set_header Accept $accept;
... a lot of configurations here ...
proxy_pass http://my_upstream;
}
如果将作为proxy_set_header
第二个参数的空字符串传递给 nginx,则根本不会设置标头。如果您的请求不会被location = /A
块捕获,则$accept
变量在location = /B
块中将为空值。
更新
如果请求被第二个位置块捕获,则上面给出的配置将清除Accept
HTTP标头。如果要保留它,可以使用更复杂的配置:
map $accept $accept_header {
"" $http_accept;
default $accept;
}
server {
...
location = /A {
set $accept "json";
rewrite /A /B;
}
location = /B {
proxy_set_header Accept $accept_header;
... a lot of configurations here ...
proxy_pass http://my_upstream;
}
...
}