HAProxy-URL重定向&改写 [英] HAProxy - URL redirection & rewriting

查看:191
本文介绍了HAProxy-URL重定向&改写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对haproxy设置完全陌生.我想在tomcat服务器上设置haproxy.

I am completely new to haproxy setup. I want to setup haproxy on top of tomcat servers.

以下配置适用于tomcat应用程序.

The below configuration works well for tomcat applications.

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

但是我不希望用户输入完整的URL.因此,当用户访问web1.example.com时,它需要从tomcat webapp目录中的服务器应用程序.我也不想改变网址.

But i dont want user to enter the complete url. so when a user hits web1.example.com it need to server application from a tomcat webapp directory. Also i dont want the url changed.

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

使用URL重定向和URL重写是否可能?如果是,请帮助我提供示例配置.

Is this possible with a url redirection and url rewriting? If yes please help me with a sample configuration.

任何帮助将不胜感激.

谢谢

推荐答案

这很丑陋,您不应这样做,它会导致静态对象的重定向,引荐来源网址和基本URL出现各种问题.使用reqrep(重写请求)和rsprep(重写位置)是微不足道的,但是您最好切换到一个更聪明的主意,而不要故意破坏您的站点,然后一直抱怨自己不断地断开链接在HTML代码中等等...总之,不要这样做!

This is ugly, you should not do that, it causes all sort of issues with redirects, referrers and base URLs for static objects. It's trivial to do with reqrep (to rewrite the request) and rsprep (to rewrite the location), but you'd better switch to a more clever idea than break your site on purpose and then complain all the time that you constantly have broken links in the HTML code etc... In short, don't do this!

这篇关于HAProxy-URL重定向&改写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆