HTTP 状态代码和 DNS 循环

发布于 2024-07-25 23:47:51 字数 542 浏览 7 评论 0原文

假设我有两台服务器,并且设置了 DNS 循环,如下所示:

www   IN  A   192.168.0.2
www   IN  A   192.168.0.3

从此 常见问题解答,它指出“所有最新的浏览器(IE、Firefox、Safari 和 Chrome)都支持客户端重试(有时称为浏览器重试),因此当由于服务器关闭而超时时,它会执行重试。将重试并命中循环中的下一个服务器”。

我的问题是:如果我想让192.168.0.2中的Web服务器保持运行,它应该返回什么(HTTP状态代码?连接拒绝?)以便某些请求(例如主机头= cde.com)被重定向到192.168。 0.3?

更新: 或者如果主机标头不匹配,我应该关闭 tcp 套接字吗?

Suppose I have two servers and I have set up DNS round robin as following:

www   IN  A   192.168.0.2
www   IN  A   192.168.0.3

From this FAQ, it states that "all of the latest browsers (IE, Firefox, Safari, and Chrome) support a client retry (sometimes called browser retry). So when it times out because a server is down, it will retry and hit the next server in the round robin".

My question is: If I want to let the web server in 192.168.0.2 stay running, what should it return (HTTP status code? connection refuse?) so that some request (e.g. host header = cde.com) are redirected to 192.168.0.3?

UPDATE:
Or should I just close the tcp socket if the host header does not match?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请叫√我孤独 2024-08-01 23:47:51

我认为您所指的重试发生在 TCP/IP 级别 - 如果您返回 HTTP 响应,您几乎是在说“嗨!我是网络服务器!我还活着!”

那么您可以尝试在 .2 服务器上使用 iptables 阻止所有端口 80 流量,也许使用一些额外的规则来让您继续测试?

编辑:因为那不会飞,我建议在网络服务器前面放置一些HTTP级别的东西,例如 haproxy,让您平衡和管理传入请求。

I think the retry you are referring to is occurring at the TCP/IP level - if you return an HTTP response, you are pretty much saying "Hi there! I'm a webserver! I'm alive!"

What you could try then is blocking all port 80 traffic using iptables on the .2 server, perhaps with some extra rules to let you continue testing?

Edit: since that won't fly, I'd suggest putting something at the HTTP level in front of the webservers, such as haproxy, to let you balance and manage the incoming requests.

┾廆蒐ゝ 2024-08-01 23:47:51

对于 Mozilla 来说,重试基本上意味着:如果与第一个 IP 地址建立连接失败(例如主机无​​法访问、连接建立超时或连接被拒绝),则将使用第二个 IP 地址。

如果有人真的想知道的话,我可能可以找到代码的 lxr 链接。

(对于代理自动配置文件,还有更复杂的行为)。

因此,在这些情况下,您的网络服务器实际上并未编写浏览器收到的响应。 因此,无需编码。

In the case of Mozilla, the retry basically means: if there is a connection establishment failure (like host unreachable, connection establishment timeout, or connection refused) to the first IP address, the second IP address will be used.

I could probably find the lxr link to the code, if someone really wanted to know.

(For Proxy Auto Config files, there is a more complicated behavior as well).

So, in these cases, they would be situation where your web server does not actually compose a response that the browser receives. So, no coding required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文