我们有几个haproxy配置在大多数情况下运行良好。 在我们的场景中,我们只是根据域名路由请求。 这是一个域的示例,drawmessage.com:
frontend http
bind *:80
redirect prefix http://app.drawmessage.com code 301 if { hdr_dom(host) -i www.app.drawmessage.com }
redirect prefix http://drawmessage.com code 301 if { hdr_dom(host) -i www.drawmessage.com }
redirect prefix https://drawmessage.com code 301 if { hdr_dom(host) -i drawmessage.com }
use_backend http:app.drawmessage.com if { hdr_dom(host) -i app.drawmessage.com }
use_backend http:app.drawmessage.com if { hdr_dom(host) -i app-drawmessage-com.d250.hu }
use_backend http:drawmessage.com if { hdr_dom(host) -i drawmessage.com }
use_backend http:drawmessage.com if { hdr_dom(host) -i drawmessage-com.d250.hu }
还有其他域名,仅针对此域名进行过滤。正如您所看到的,在重定向www之后,我们为drawmessage.com应用了一个特殊的重定向,但理论上不适用于app.drawmessage.com。
frontend https
bind *:443 ssl crt /var/haproxy
redirect prefix https://app.drawmessage.com code 301 if { hdr_dom(host) -i www.app.drawmessage.com }
redirect prefix https://drawmessage.com code 301 if { hdr_dom(host) -i www.drawmessage.com }
use_backend https:app.drawmessage.com if { hdr_dom(host) -i app.drawmessage.com }
use_backend https:app.drawmessage.com if { hdr_dom(host) -i app-drawmessage-com.d250.hu }
use_backend https:drawmessage.com if { hdr_dom(host) -i drawmessage.com }
use_backend https:drawmessage.com if { hdr_dom(host) -i drawmessage-com.d250.hu }
问题在于,实际上,我们不希望重定向到子域app.drawmessage.com的https,但由于我们有域的重定向,因此重定向规则适用于两者。以某种方式重新排序规则,以便排序与我们想要实现的配置匹配确实产生相同的结果,并且我们得到haproxy警告:
a 'redirect' rule placed after a 'use_backend' rule will still be processed before.
如果配置行的顺序影响处理请求的顺序,那么排序本身就是配置参数,为什么在use_backend规则之前处理重定向规则? ...
任何人都有一个建议如何实现基于域的路由,正确的重定向偏好?我更喜欢干净简单的方式,..
答案 0 :(得分:2)
不要使用WARNING: Found unknown Windows version: Windows 10
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
java.lang.UnsatisfiedLinkError: no jinput-dx8_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at net.java.games.input.DirectInputEnvironmentPlugin$1.run(DirectInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.DirectInputEnvironmentPlugin.loadLibrary(DirectInputEnvironmentPlugin.java:67)
at net.java.games.input.DirectInputEnvironmentPlugin.<clinit>(DirectInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:45)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at GamePadTut.main(GamePadTut.java:11)
java.lang.UnsatisfiedLinkError: no jinput-raw_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at net.java.games.input.RawInputEnvironmentPlugin$1.run(RawInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.RawInputEnvironmentPlugin.loadLibrary(RawInputEnvironmentPlugin.java:67)
at net.java.games.input.RawInputEnvironmentPlugin.<clinit>(RawInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at GamePadTut.main(GamePadTut.java:11)
。只需使用hdr_dom()
。
hdr()
redirect prefix https://drawmessage.com code 301 if { hdr(host) -i drawmessage.com }
后缀表示您希望将稍后给出的值与指定标头中找到的任意数量的完整,连续的域名类似标记相匹配,因此您提供的模式必须从紧跟在_dom
之后的字符串或,必须在字符串或的末尾结束,后面紧跟.
。这不是您想要做的,因此.
不是正确的提取方式。
符号可能暗示您将左值与右值进行比较,但比较实际上是对左值的正确值。
a&#39;重定向&#39;在“use_backend”之后放置的规则&#39;规则仍将在之前处理,因为这些指令由HAProxy代码的不同部分处理,处理请求处理的不同阶段。在每个规则类别中,订单被保留,但重定向在开头附近处理,后端选择接近请求处理结束。