Rewrite urls for response with absolute urls


Hi all.

I have Jenkins running on Tomcat with HAProxy as a reverse proxy in front of it. That works kind of OK and my haproxy.conf is listet at the end of my post, but I have a problem with rewriting paths in the response.

when I GET I get the correct HTML returned, but all links are absolute to the host’s root, and thus my webbrowser cannot fetch them as it tries e.g. instead of

If only it was a matter of rewriting domains, I would be home safe, but because of that pesky start o the path I am stuck.
I have tried to change the server and/or host to as in the configuration file below.

Can what I want be one?
How? Any pointers and hints are appreciated. (I tried setting the JENKINS_URL in the jenkins control panel, which didn’t work. Also a generic solution would be convenient.)


I am running HA-Proxy version 1.6.6 2016/06/26

My haproxy.conf:

    maxconn 4096

    log  global
    maxconn  2000
    mode  http
    option  redispatch
    option  forwardfor
    option  http-server-close
    retries  3
    timeout  http-request 10s
    timeout  queue 1m
    timeout  connect 10s
    timeout  client 1m
    timeout  server 1m
    timeout  check 10s

frontend http-in
    bind *:80
    reqadd  X-Forwarded-Proto:\ http

    acl is_MyWebApp path_beg /MyWebApp
    use_backend MyWebApp if is_MyWebApp
backend MyWebApp
    option httpclose
    option forwardfor
    http-response  set-header Location
    http-response  set-header Server
    http-response  set-header Host    
    reqrep ^([^\ ]*\ /)MyWebApp[/]?(.*)     \1\2
    server s2  maxconn 32



I’m looking for a simalar solution .Have appended /Jenkins and then need to forward to the server .


This should be it (untested):
reqrep ^([^\ :]*)\ /(.*) \1\ /MyWebApp/\2


The URL now goes to login page , but then after login it shows page not found as Jenkins does not resolve the url


I can help you to setup haproxy if you know what has to be done. Can’t help you with your end application though.


I require proxy-ip/jenkins to be the proxy url for Jenkins host ie

I have few other acls configurd in haproxy config.

Jenkins page adds /login (proxy-ip/login) and the frontend rule in haproxy fails to find suitable acl. I get 404.

Current config:-

frontend http-in
bind *:80
option http-server-close
option forwardfor
acl has_jenkins path_beg /jenkins
use_backend jenkins_server if has_jenkins
default_backend jenkins_server

backend jenkins_server
balance roundrobin
reqrep ^([^\ ]\ /)jenkins[/]?(.) \1\2
server ws2


The ACL on the frontend matches what the browser sends you, (so before the rewrite). It would not make any sense otherwise.

What you would have to explain, is what you expect from haproxy on a HTTP level exactly.


Ok , Jenkins listens on Once you hit the URL , it shows in the browser , which then loads the login page . You enter the credentials and after successful authentication Jenkins will take you to , which means you have logged in . All good now

I have HAPRoxy installed on another server , and need to give my users /jenkins , so that it redirects to the above URL .
The first request to the same through HAProxy happens , perfectly , as it finds the prefix and redirects to backend , that loads the login page , with the URL showing /login in the address bar. You see the Jenkins application as prefixed it with /login , with the HAPROXYIP .
Once the login page is shown , and enter the credentials , Jenkins get 401 as it does not find the actual ACL now for /login.