2012-12-23 69 views
0

我對haproxy設置完全陌生。我想在tomcat服務器上設置haproxy。HAProxy - URL重定向和重寫

下面的配置適用於tomcat應用程序。

global 
    log 127.0.0.1 local0 
    log 127.0.0.1 local1 notice 
    maxconn 4096 
    user haproxy 
    group haproxy 

defaults 

    log  global 
    mode http 
    option httplog 
    option dontlognull 
    retries 3 
    option redispatch 
    maxconn 20000 
    contimeout  5000 
    clitimeout  50000 
    srvtimeout  50000 

listen webfarm 100.100.100.100:80 
    mode http 
    stats enable 
    stats uri /haproxy?statis 
    stats realm Haproxy\ Auth 
    stats auth user:password 
    balance leastconn 
    cookie JSESSIONID insert indirect nocache 
    option httpclose 
    option forwardfor 
    server web01 192.168.1.1:8080 cookie A check 
    server web02 192.168.1.2:8080 cookie B check 

但我不希望用戶輸入完整的網址。所以當用戶點擊web1.example.com時,它需要從tomcat webapp目錄中的服務器應用程序。另外我不想要更改網址。

Example : http://web1.example.com -> http://192.168.1.1:8080/applications/web1 & http://192.168.1.2:8080/applications/web1 

這是可能的與URL重定向和URL重寫?如果是,請幫助我進行示例配置。

任何幫助將非常感激。

感謝

回答

2

這是醜陋的,你不應該這樣做,將導致所有排序與重定向,引薦和基本URL靜態對象的問題。使用reqrep(重寫請求)和rsprep(重寫位置)很簡單,但最好轉換爲更聰明的主意,而不是故意破壞網站,然後始終抱怨鏈接不斷出現斷裂在HTML代碼等...總之,不要這樣做!

+0

目前我正在使用Apache Proxy平衡器來完成所有這些,但有點惱人的破管問題。所以想到用HAProxy試用它。但是,你提出了好點。我現在放棄這個想法。 謝謝。 – parames