给定一个正在运行的后端:
172.18.1.125:8888
卷曲测试:
curl --location --request GET "http://172.18.1.125:8888/oauth/sign-key"
sample_response //>> HERE IS RESPONSE
在另一台主机上,我安装并配置了 haproxy:
global
log /dev/log local0
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
debug
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
ssl-default-bind-ciphers PROFILE=SYSTEM
ssl-default-server-ciphers PROFILE=SYSTEM
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
frontend api_gateway
bind :80
acl PATH_auth path_beg /api/authorization/
use_backend be_auth if PATH_auth
backend be_auth
server s1 172.18.1.125:8888
http-request set-header Host 172.18.1.125
之后我使用 curl 来测试我的 haproxy:
curl --location --request GET "http://localhost/api/authorization/oauth/sign-key"
我预计该请求将被路由至:
http://172.18.1.125:8888/oauth/sign-key
但是我得到的却是 503 错误:
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>
我错什么了或者遗漏了什么?
答案1
我猜你会http://172.18.1.125:8888/api/authorization/oauth/sign-key而不是像您期望的那样使用 172.18.1.125:8888/oauth/sign-key,因为您没有执行任何操作来删除“api/authorization”...尝试这个后端:
backend be_auth
http-request set-path %[path,regsub(^/api/authorization/,/)]
server s1 172.18.1.125:8888