大网数据广告活动
服务器运维问答

HAProxy request rewrite

· 52CE 我爱测

I am trying to setup pass proxy with HAProxy. Version :- HA-Proxy version 1.7.5 2017/04/03 I have two URL abc.com/foo and abc.com/bar and I want it to get redirected to my backend servers which are serving request as 10.0.0.1/xyz…

问题原文

原帖链接 · Faisal Muazzam · CC BY-SA 3.0

I am trying to setup pass proxy with HAProxy.

Version :- HA-Proxy version 1.7.5 2017/04/03

I have two URL abc.com/foo and abc.com/bar and I want it to get redirected to my backend servers which are serving request as 10.0.0.1/xyz/

For example, if my requests are coming as abc.com/foo/login, so this request should go to my backend server as 10.0.0.1:7003/xyz/login but the front end should only show abc.com/foo/login.

I tried using below

 "http-request redirect code 301 location http://%[hdr(host)]%[url,regsub(^/foo/,/bar/,)] if { path_beg /foo }"

but it is changing the URL as abc.com/xyz

I have been using nginx as of now, below is my configuration of the same.

server {
   listen 8443;
        underscores_in_headers on;

location /Recharge {
        proxy_pass http://backend/RetailerApp;
        proxy_read_timeout 15;
}

location /Gateway {
        proxy_pass http://backend/RetailerApp;
        proxy_read_timeout 15;
}
}

upstream backend_preprod {
   server 10.5.214.237:7005;
   server 10.5.214.237:7004;
}

已采纳解答

原帖链接 · user373333 · CC BY-SA 3.0

You don't want to use redirect because that will redirect the client to the given URL. You only need to rewrite the request URL.

reqrep ^([^\ :]*)\ /foo/(.*)     \1\ /xyz/\2
reqrep ^([^\ :]*)\ /bar/(.*)     \1\ /xyz/\2

https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#reqrep

Client will still see the /foo or /bar path, this will only rewrite it in communication between the proxy and the backend server.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。