Quantcast
Channel: HAProxy community - Latest topics
Viewing all articles
Browse latest Browse all 4740

Reverse proxy redirect to servers based on url root path

$
0
0

I am new to HAProxy and struggling to understand how things to configure.
I have found just one example for Grafana, though I am not able to expand this to other applications.

This is my setup:

I have a couple of docker containers running on a single host. The containers are attached to the same bridged network. The containers deliver services on different ports, e.g openhab on 8080, Grafana on 3000, NodeRed on 1880, and so non. These ports are not exposed through the bridge.

What I want to do is to run a haproxy container as a reverse proxy on the bridged network and expose just 80 to the host network.
The routing to the services should than happen based on the root URL path, e.g host/openhab for openhab, host/grafana for Grafana,…

this is my config:

global
  log stdout format raw local0
defaults
  log global
  mode http
  option httplog
  timeout client          30s
  timeout server          30s
  timeout connect         30s

frontend http-in
  bind *:80
  use_backend grafana_backend if { path /grafana } or { path_beg /grafana/ }
  use_backend nodered_backend if { path /nodered } or { path_beg /nodered/ }
  use_backend sbserver_backend if { path /sbserver } or { path_beg /sbserver/ }
  use_backend openhab_backend if { path /openhab } or { path_beg /openhab/ } 

backend grafana_backend
  mode http
  http-request set-path %[path,regsub(^/grafana/?,/)]
  server grafana grafana:3000

backend nodered_backend
  mode http
  http-request set-path %[path,regsub(^/nodered/?,/)]
server node-red node-red:1880

backend openhab_backend
  http-request set-path %[path,regsub(^/openhab/?,/)]
  server openhab openhab:8080

backend sbserver_backend
  mode http
  http-request set-path %[path,regsub(^/sbserver/?,/)]
  server sb-server sbserver:9000

The problem I have, for example for openhab_backend, is that the response from the server contains resources which when requested by the browser are not routed to the corresponding backend .
Here is an example log output for the openhab:

Proxy http-in stopped (cumulated conns: FE: 9, BE: 17).,
[NOTICE]   (1) : haproxy version is 2.5.0-f2e0833,
[NOTICE]   (1) : path to executable is /usr/local/sbin/haproxy,
[WARNING]  (1) : Exiting Master process...,
[WARNING]  (8) : Proxy http-in stopped (cumulated conns: FE: 9, BE: 17).,
[WARNING]  (1) : Current worker (8) exited with code 0 (Exit),
[WARNING]  (1) : All workers exited. Exiting... (0),
[NOTICE]   (1) : New worker (8) forked,
[NOTICE]   (1) : Loading success.,
192.168.3.55:62217 [12/Dec/2021:16:13:38.119] http-in openhab_backend/openhab 0/0/1/2/3 304 73 - - ---- 1/1/0/0/0 0/0 "GET /openhab/ HTTP/1.1",
192.168.3.55:62217 [12/Dec/2021:16:13:38.207] http-in http-in/<NOSRV> -1/-1/-1/-1/0 503 217 - - SC-- 1/1/0/0/0 0/0 "GET /css/app.css HTTP/1.1",
192.168.3.55:62217 [12/Dec/2021:16:13:38.208] http-in http-in/<NOSRV> -1/-1/-1/-1/0 503 217 - - SC-- 1/1/0/0/0 0/0 "GET /js/app.js HTTP/1.1",
192.168.3.55:62217 [12/Dec/2021:16:13:38.263] http-in http-in/<NOSRV> -1/-1/-1/-1/0 503 217 - - SC-- 1/1/0/0/0 0/0 "GET /res/icons/favicon.svg HTTP/1.1",
192.168.3.55:62217 [12/Dec/2021:16:13:38.266] http-in http-in/<NOSRV> -1/-1/-1/-1/0 503 217 - - SC-- 1/1/0/0/0 0/0 "GET /res/icons/128x128.png HTTP/1.1"

Is this problem solvable?

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4740

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>