Hello,
I’m new in HAProxy can you tell my how I can properly configuring rewrite in HAproxy?
frontend main
bind *:80
acl simple hdr_end(host) -i simpledomain.com
use_backend app if simple
mode http
backend app
mode http
server srv1 192.168.10.3:8080
reqrep ^([^\ :])\ /(.) \1\ /simpleapp/\2 |<-- this line isn’t work
I have this config and I want to do this forwarding:
simpledomain.com —> 192.168.10.3:8080/simpleapp
(where address simpledomain.com = 192.168.10.5:80.)
The forwarding work only that, without rewrite /simpleapp:
simpledomain.com —> 192.168.10.3:8080
What should be changed in this configuration to make it work?
Regards,
Michael
Hi Michael -
You could do something like the following:
backend app
mode http
server srv1 192.168.10.3:8080
http-request set-path /simpleapp%[path,regsub(/,)]
We do something similar at my company.
Hope that helps!
Hello,
Thank you for respons.
Now I have this configuration:
frontend main
bind *:80
acl simple hdr_end(host) -i simpledomain.com
use_backend app if simple
mode http
backend app
mode http
server srv1 192.168.10.3:8080
http-request set-path /simpleapp%[path,regsub(/,)]
But I have this error when I start haproxy:
[root@localhost ~]# service haproxy restart
[ALERT] 083/163150 (2599) : parsing [/etc/haproxy/haproxy.cfg:131]: ‘http-request’ expects ‘allow’, ‘deny’, ‘auth’, ‘redirect’, ‘tarpit’, ‘add-header’, ‘set-header’, ‘replace-header’, ‘replace-value’, ‘set-nice’, ‘set-tos’, ‘set-mark’, ‘set-log-level’, ‘add-acl’, ‘del-acl’, ‘del-map’, ‘set-map’, but got ‘set-path’.
[ALERT] 083/163150 (2599) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
Errors in configuration file, check with haproxy check
The line 131 in haproxy.cfg is:
" http-request set-path /simpleapp%[path,regsub(/,)]"
I have version 1.5.4 and in this v. ‘set-path’ doesn’t work. It’s work in v.1.7
Regards,
Michael