【问题标题】:haproxy configuration for rewriting to /myapp用于重写到 /myapp 的 haproxy 配置
【发布时间】:2017-12-05 07:39:17
【问题描述】:

这是我的 haproxy 配置

global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 16384
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/run/haproxy.cmd

defaults
mode http
log global
option httplog
option dontlognull
option httpclose
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 20s
timeout client 45s
timeout server 45s
timeout check 20s
maxconn 16384

listen stats :9000
mode http
stats enable
stats uri /haproxy
stats realm HAProxy\ Statistics
stats auth haproxy:password
stats admin if TRUE

listen http :80
    #balance leastconn
    #balance roundrobin
    balance source
    option http-server-close
    option forwardfor
    server web1 10.0.2.10:8080 check inter 3000 rise 2 fall 3
    server web2 10.0.2.11:8080 check inter 3000 rise 2 fall 3
# acl has_www hdr_beg(host) -i www
# http-request redirect code 301 location myapp

它是这样工作的:

我输入http://www.example.com:8000http://www.example.com,所以它会转到jboss 的8080 端口。 我的应用程序实际上可以通过example.com/suite 访问,但是由于 ISP 阻止了端口 80,这就是我使用端口 8000 的原因,因此;我的应用程序可以通过example.com:8000/mypp访问

我想使用 haproxy 配置将输入 example.com:8000 的人转发到 example.com:8000/myapp

如何实现呢? 我错过了什么对吗?

【问题讨论】:

    标签: redirect configuration reverse-proxy haproxy forward


    【解决方案1】:

    当您在后端节点部分定义“服务器”时,您可以将 URI 附加到 IP 和端口,如下所示,以实现您要查找的内容,

    defaults
        log global
        mode    http
        option  httplog
        option  dontlognull
            timeout connect 5000
            timeout client  50000
            timeout server  50000
    
    frontend localnodes
        bind 0.0.0.0:9876
        mode http
        default_backend nodes
    
    backend nodes
        mode http
        balance roundrobin
        option forwardfor
        http-request set-header X-Forwarded-Port %[dst_port]
        http-request add-header X-Forwarded-Proto https if { ssl_fc }
        option httpchk HEAD / HTTP/1.1\r\nHost:localhost
        server web01 127.0.0.1:8443/**myApp** check  
    

    【讨论】:

      猜你喜欢
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      相关资源
      最近更新 更多