我在CentOS 7 Linux上运行一个embedded在Wordpress / Jetty后面的HAProxy 1.5网页游戏。
该网站可以作为http和https访问。
我已经修改WordPress的显示播放器configuration文件页面的url如下所示:
https://slova.de/player-12345
其中12345是我的网页游戏中的数字播放器ID。
这工作得很好,但我想简化上面的url
https://slova.de/12345
然后使用HAProxy 将“player-”部分预先设置为仅限数字的path 。
所以我已经添加到/etc/haproxy/haproxy.cfg文件的行:
http-request redirect code 301 prefix /player- if { path_end /5 }
但是,由于某些原因,导致url不完整:
https://slova.de/player-/player-/player-/player-/player-/player-/player-/player-/player-/player-/player-/player-/player-/player-/播放器- /播放器- /播放器- /播放器- /播放器- /播放器- /播放器- / 5
下面是我完整的haproxy.cfg文件来提供更多的上下文:
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
这意味着您要发送一个301redirect响应到每个请求在URL的末尾有数字5 。
所以,如果您的第一个请求是http://www.example.com/5 ,那么您的configuration会发送HTTP 301redirect到http://www.example.com/player-5 。 浏览器然后请求这个URL,并且HAProxy再次发送HTTP 301redirect,现在到http://www.example.com/player-/player-5等等,直到一些URL长度极限被达到。
我假设你不想在这里做301redirect,但附加player-前缀到Jetty的请求。 要做到这一点,你需要使用http-request set-path指令。
但是,如果您想要301 redirect ,那么您需要优化条件,以便redirect只在URL中没有player-前缀的情况下完成。
例如,这可以工作:
http-request redirect code 301 prefix /player- if { path_end /5 and !path_end /player-5 }
我自己并没有使用HAProxy,所以这只是基于HAProxy文档以及我对ACL如何工作的解释。