506的官方解释和翻译是这样的:
506
Variant Also Negotiates
代表服务器存在内部配置错误:被请求的协商变元资源被配置为在透明内容协商中使用自己,因此在一个协商处理中不是一个合适的重点。
请问除了写这句话的人以外,谁能读懂???
所以我们自己来找原因吧!
我们在apache目录自己找一下这句话:
andy@AndyMacBookPro:/etc/apache2$ grep -r HTTP_VARIANT_ALSO_VARIES ./*
./extra/httpd-multilang-errordoc.conf:ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
./original/extra/httpd-multilang-errordoc.conf:ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
vi httpd-multilang-errordoc.conf 一下:
Alias /error/ "/usr/share/httpd/error/"
可以知道apache的error ducument目录:
/usr/share/httpd/error/
这个文件:
/usr/share/httpd/error/HTTP_VARIANT_ALSO_VARIES.html.var
其实是apache返回506错误时的response模板。
知道这个,我们再往下,我们从网上看到对506 status的这种解释:
506 Variant Also Negotiates
The server is not properly configured. To resolve this issue, contact your system administrator.
告诉我们的是506错误是因为服务器没有正确配置。
因为网上资料实在有限,所以我们准备下载apache的httpd服务器的源码来自己找原因,我这里有两个地址,一个git一个源码:
git clone git://git.apache.org/httpd.git httpd
或者
wget http://apache.fayea.com/httpd/httpd-2.4.12.tar.gz
我们在这个文件中找到了关于HTTP_VARIANT_ALSO_VARIES的逻辑:
httpd-2.4.12/modules/mappers/mod_negotiation.c
/* The variant selection algorithm told us to return a "Choice"
* response. This is the normal variant response, with
* some extra headers. First, ensure that the chosen
* variant did or will not itself engage in transparent negotiation.
* If not, set the appropriate headers, and fall through to
* the normal variant handling
*/
/* This catches the error that a transparent type map selects a
* transparent multiviews resource as the best variant.
*
* XXX: We do not signal an error if a transparent type map
* selects a _non_transparent multiviews resource as the best
* variant, because we can generate a legal negotiation response
* in this case. In this case, the vlist_validator of the
* nontransparent subrequest will be lost however. This could
* lead to cases in which a change in the set of variants or the
* negotiation algorithm of the nontransparent resource is never
* propagated up to a HTTP/1.1 cache which interprets Vary. To be
* completely on the safe side we should return HTTP_VARIANT_ALSO_VARIES
* for this type of recursive negotiation too.
*/
if (neg->is_transparent &&
apr_table_get(sub_req->err_headers_out, "TCN")) {
return HTTP_VARIANT_ALSO_VARIES;
}
/* This catches the error that a transparent type map recursively
* selects, as the best variant, another type map which itself
* causes transparent negotiation to be done.
*
* XXX: Actually, we catch this error by catching all cases of
* type map recursion. There are some borderline recursive type
* map arrangements which would not produce transparent
* negotiation protocol errors or lack of cache propagation
* problems, but such arrangements are very hard to detect at this
* point in the control flow, so we do not bother to single them
* out.
*
* Recursive type maps imply a recursive arrangement of negotiated
* resources which is visible to outside clients, and this is not
* supported by the transparent negotiation caching protocols, so
* if we are to have generic support for recursive type maps, we
* have to create some configuration setting which makes all type
* maps non-transparent when recursion is enabled. Also, if we
* want recursive type map support which ensures propagation of
* type map changes into HTTP/1.1 caches that handle Vary, we
* would have to extend the current mechanism for generating
* variant list validators.
*/
if (sub_req->handler && strcmp(sub_req->handler, "type-map") == 0) {
return HTTP_VARIANT_ALSO_VARIES;
}