某些移动设备向我们的服务器发送以下不正确的请求:
GET / HTTP/1.0 Accept: User-Agent : xxx
空的Accept标头会导致我们的Ruby on Rails服务器返回一个500错误。
在Apache中,以下指令允许我们在将头发送到应用程序RoR服务器之前重写头文件,以便处理破碎的设备:
RequestHeader edit Accept ^$ "*/*" early
我们目前正在设置nginx,但是实现相同的解决scheme却很困难。 我们可以设置:
proxy_set_header Accept */*;
但是,这似乎必须无条件地完成。 每当试图做:
if ($http_accept !~ ".") { proxy_set_header Accept */*; }
它抱怨的消息:
"proxy_set_header" directive is not allowed here
因此,使用nginx,在将请求发送到应用程序服务器之前,如何将HTTP Accept头设置为空时设置为*/* ?
尝试这个
set $acceptHeader $http_accept; if ($acceptHeader !~ ".") { set $acceptHeader '/'; } proxy_set_header Accept $acceptHeader;
map $http_accept $accept_header { default $http_accept; "" */*; } server { ... proxy_set_header Accept $accept_header; }