根据主机名进行路由时,如何在本地测试haproxy? [英] How do I locally test haproxy when routing based on host name?

查看:57
本文介绍了根据主机名进行路由时,如何在本地测试haproxy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的haproxy配置,它根据请求的主机(通过acl + hdr_dom)路由到后端.如果要在本地测试配置,则必须更改要测试的主机的分辨率(例如,通过更改hosts文件将host解析为127.0.0.1).然后,我可以使用wget或curl在本地测试haproxy配置,然后再重置hosts文件.

I have a fairly complex haproxy configuration that routes to backends based on the host of the request (via acl + hdr_dom). If I want to test the configuration locally, I have to change the resolution of the hosts I want to test (for example, by changing hosts file to resolve host to 127.0.0.1). I can then use wget or curl to test the haproxy configuration locally, and reset the hosts file afterward.

但是,我想进行自动化测试,而在自动化测试中更改系统级别的内容会让我感到紧张.在我走上自动更改主机文件的路径之前,有没有办法告诉haproxy假装此请求是向xxx.yyy.com提出的"?我还能采取其他方法吗?

However, I want to have automated tests, and changing system level things in an automated test makes me nervous. Before I go down the path of changing the hosts file in an automatic way, is there a way to tell haproxy "pretend this request was made to xxx.yyy.com"? Is there some other approach I can take?

谢谢

推荐答案

有没有办法告诉haproxy假装此请求是向xxx.yyy.com发出的?"

is there a way to tell haproxy "pretend this request was made to xxx.yyy.com"?

我认为这是错误的问题.正确的问题是如何告诉curl example.com的IP地址是127.0.0.1?"

I believe that's the wrong question. The correct question is "How can I tell curl that example.com's IP address is 127.0.0.1?"

答案是-resolve .

curl -v --resolve example.com:80:127.0.0.1 http://example.com
curl -v --resolve example.com:443:127.0.0.1 https://example.com

这仅将答案(127.0.0.1)预加载到curl的DNS缓存中,仅用于该调用,这显然会诱使它不进行DNS查找,因为它认为已经进行了查找.相反,它将连接到您指定的IP地址.

This preloads the answer (127.0.0.1) into curl's DNS cache for that invocation only, which apparently tricks it into not actually doing a DNS lookup, because it thinks it already did. Instead, it will connect to the IP address you specify.

这篇关于根据主机名进行路由时,如何在本地测试haproxy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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