I run a web game embedded in Wordpress/Jetty behind HAProxy 1.5 on CentOS 7 Linux.
The website can be accessed both as http
and https
.
I have modified Wordpress to display player profile pages at the URLs like:
https://slova.de/player-12345
where 12345
is a numeric player id in my web game.
This works well, but I would like to simplify the above URLs to
https://slova.de/12345
and then use HAProxy to prepend the "player-" part to numeric-only paths.
So I have added to /etc/haproxy/haproxy.cfg
file the line:
http-request redirect code 301 prefix /player- if { path_end /5 }
This results however in the broken URL for some reason:
Below is my complete haproxy.cfg
file to provide more context:
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
tune.ssl.default-dh-param 2048
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
# for WebSocket connections
timeout tunnel 1h
timeout client-fin 1m
frontend public
bind 144.76.184.151:80
bind 144.76.184.151:443 ssl crt /etc/pki/tls/certs/slova.de.pem no-sslv3
http-request deny if { path_beg /xmlrpc.php }
http-request redirect code 301 prefix /player- if { path_end /5 }
default_backend jetty
backend jetty
server domain 127.0.0.1:8080 send-proxy
This means you are sending a 301 redirect response to every request that has the number
5
in the end of the URL.So, if your first request is for
http://www.example.com/5
, your configuration would send a HTTP 301 redirect to URLhttp://www.example.com/player-5
. The browser then requests this URL, and HAProxy again sends the HTTP 301 redirect, now tohttp://www.example.com/player-/player-5
and so on, until some URL length limit is reached.I assume that you don't want to do a 301 redirect here, but attach the
player-
prefix to the request going to Jetty. To make this happen, you need to use thehttp-request set-path
directive.However, if you want to do a
301 redirect
, then you need to refine your condition so that the redirect is only done when there is noplayer-
prefix in the URL.For example, this could work:
I haven't used HAProxy myself, so this is only based on the HAProxy documentation and my interpretation on how its ACLs work.