
reqrep을 사용하여 uri의 일부를 다시 작성하려고 합니다.
haproxy.cfg(원본)
global
log 127.0.0.1 local2
daemon
maxconn 256
defaults
mode http
log global
option httplog
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend haproxy_in
bind *:8080
default_backend myapp
backend myapp
server app1 localhost:8123 check
이렇게 하면 예상한 haproxy 로그가 표시됩니다. 참고 저는 POST를 처리할 수 없는 더미 Python 서버를 사용하고 있으므로 501은 문제가 되지 않습니다. 단지 요청이 라우팅되었다는 사실만이 제가 찾고 있는 것입니다.
haproxy_in myapp/app1 0/0/0/1/5 501 379 - - ---- 0/0/0/0/0 0/0 "POST /please/rewrite/this/ HTTP/1.1
또한 내 서버 로그가 다음과 같이 표시됩니다.
"POST /please/rewrite/this/ HTTP/1.1" 501 -
haproxy.cdf(reqrep 포함)
global
log 127.0.0.1 local2
daemon
maxconn 256
defaults
mode http
log global
option httplog
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend haproxy_in
bind *:8080
default_backend myapp
backend myapp
reqrep ^([^\ :]*\ /) "POST\ /test\ HTTP/1.1"
server app1 localhost:8123 check
reqrep을 추가하면 haproxy에서 오류 메시지가 나타납니다.
haproxy_in myapp/<NOSRV> -1/-1/-1/-1/1 400 187 - - PR-- 0/0/0/0/3 0/0 "POST /please/rewrite/this/ HTTP/1.1"
내 요청이 잘못된 것 같은데요? 요청이 haproxy에서 벗어나지 않는 것 같습니다. 요청이 다시 작성된 내용을 어떻게 확인할 수 있나요? 다른 정규식을 사용하여 여러 가지 다른 reqrep 명령을 시도했는데 모두 동일한 오류가 발생하는 것 같습니다.
내 haproxy 버전은 1.5.16입니다.
답변1
요청3개의 매개변수를 사용합니다 <search> <string> <cond>
.
<search>
:은 URL입니다(예: www.somedomain.com/please/rewrite/this/).
<string>
:는 대체 문자열입니다(예: /test).
<cond>
: 특별한 조건을 위한 것이므로 지금은 무시하세요.
이 예에서 교체는 다음을 수행합니다.
FROM: http://www.somedomain.com/please/rewrite/this/
TO: /test
다음은 교체를 수행합니다.
reqrep http://www.somedomain.com/please/rewrite/this/ http://www.somedomain.com/test
도메인 무시를 대체하려면 정규식으로 설정해야 합니다.
reqrep ^([^\ :]*)\/please/rewrite/this/ \1\/test