$http_host 和 $host 的实际区别 [英] Practical difference of $http_host and $host

查看:74
本文介绍了$http_host 和 $host 的实际区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我正在寻找在 中使用 $http_host 而不是 $host 变量的实际差异(和潜在的陷阱)nginx

As the title says, I'm looking for the practical difference (and potential pitfalls) of using $http_host instead of the $host variable in the proxy_set_header settings in nginx

当然我已经看过这个问题的答案Nginx 中 $host 和 $http_host 的区别是什么.但是除了 $host 删除端口并使用小写之外,这并没有真正解释在哪些情况下会影响我的应用程序,例如 "HTTP_HOST 何时不存在或为空价值"?是用户使用旧版浏览器还是中途通过其他代理?

Of course I have already read the answer to this question What's the difference of $host and $http_host in Nginx. But apart from $host removing the port and making lower case, that doesn't really explain in what scenarios that would affect my application, like when will the "HTTP_HOST is absent or is an empty value"? Is it when the user are using an older browser or when he/she passes through another proxy at the way?

(我使用 nginx 将流量路由到 python flask 后端应用程序(也使用flask-socket.io)

(I'm using nginx to route traffic to a python flask backend application (also using flask-socket.io)

推荐答案

实际的区别在于 $host 提供了更广泛的兼容性,特别是与过时版本的 HTTP 协议(​​例如 RFC 2068).

The practical difference is that $host provides a wider compatibility, particularly with obsolete versions of the HTTP protocol (for example RFC 2068).

$host 优于 $http_host,因为它对客户端兼容性的限制最少.而 $http_host 可能在需要严格遵守协议的应用程序中很有用.

$host is preferred over $http_host for public facing applications, as it is the least restrictive on client compatibility. Whereas $http_host might be useful in applications where strict protocol compliance would be beneficial.

这篇关于$http_host 和 $host 的实际区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆