我想在haproxy的后端添加一个path。 我不想使用redirect。 所以我尝试使用reqrep
基本上我需要什么:
前端:
resources.mydomain.com/images/path/to/resource.png
然后它需要转发到:
backend.mydomain.com/replaced/part/path/to/resource.png
这是我的cfg
frontend http-in bind 0.0.0.0:80 mode http option httplog acl path_ok path_end .gif acl path_ok path_end .jpg acl path_ok path_end .png http-request deny unless path_ok use_backend resourceBackend if path_ok backend resourceBackend reqrep ^([^\ :]*)\ /images[/]?(.*) \1\/replaced/part/\2 mode http option httpchk option forwardfor except 127.0.0.1 http-request add-header X-Forwarded-Proto https if { ssl_fc } server web-server1 backend.mydomain.com maxconn 32
我testing了我的正则expression式在https://regex101.com/ ,它似乎工作。
其实我忘了更换空间了:
frontend http-in bind 0.0.0.0:80 mode http option httplog acl path_ok path_end .gif acl path_ok path_end .jpg acl path_ok path_end .png http-request deny unless path_ok use_backend resourceBackend if path_ok backend resourceBackend # Space before /replaced reqrep ^([^\ :]*)\ /images[/]?(.*) \1\ /replaced/part/\2 mode http option httpchk option forwardfor except 127.0.0.1 http-request add-header X-Forwarded-Proto https if { ssl_fc } server web-server1 backend.mydomain.com maxconn 328