当前位置: 动力学知识库 > 问答 > 编程问答 >

reverse proxy - multiple reqirep haproxy

问题描述:

I have an haproxy 1.4 installed and I need to configure a reverse proxy in haproxy.conf that rewrites a URL from www.somedomain.com to www.otherdomain.com/bla/ble. the configuration that I am writing is here:

acl cpol_acl hdr_dom(host) -i www.somedomain.com

use_backend cpol_srv if cpol_acl

backend cpol_srv

balance leastconn

mode http

option httplog

stick on src

stick-table type ip size 10240k expire 60m

reqirep ^([^\ :]*)\ /(.*) \1\ /bla/ble\2

reqirep ^Host:\ www.somedomain.com Host:\ www.otherdomain.com

server cpol_srv www.otherdomain.com check port 80

This is working but the URL in the browser does rewrite to www.otherdomain.com/bla/ble and that's not what I want. If I remove the line

reqirep ^([^\ :]*)\ /(.*) \1\ /bla/ble\2

I only can forward to the host www.otherdomain.com but the URL in the browser stays with www.somedomain.com.

Is there any way of doing this types of reverse proxy without rewriting the browser URL?

PS: I would do this Apache style (which works) but the machine does not have any NAT to the world outside, and can only communicate to haproxy.

网友答案:

Well, after a while I figured out what has to be done.

It's not sufficient to change only the request but also have to change the response back to the original requesting host. It was also made an acl to prevent repetition of the directory url part "/bla/ble". Sticking to the example above this should be done like so:

    acl                     cpol_acl hdr_dom(host) -i www.somedomain.com
    use_backend             cpol_srv if cpol_acl


backend cpol_srv
    balance                 leastconn
    mode                    http
    option                  httplog
    stick                   on src
    stick-table             type ip size 10240k expire 60m
    **acl                     no_redir url_beg   /bla/ble/**

    reqirep                 ^Host:\ www.somedomain.com Host:\ www.otherdomain.com
    reqirep                 ^([^\ :]*)\ /(.*)       \1\ /bla/ble\2   **if !no_redir**


    **rspirep                 ^([^\ :]*)\ (.*)www.otherdomain.com/bla/ble/(.*)    \1\ \2www.somedomain.com/\3**

    server                  cpol_srv www.otherdomain.com check port 80
分享给朋友:
您可能感兴趣的文章:
随机阅读: