0

I know i have asked this before but i dint get any answers for the question.So basically i have a node js app running on port 5000.I have successfully redirected this to port 8080 using the following haproxy configuration-

frontend http-in
    mode    http

    bind *:8080

    acl path-employeeList              path_beg -i /  
    use_backend employeeList-backend   if path-employeeList


backend employeeList-backend
    mode    http

    option  httplog
    option  forwardfor

    server  appserver1  206.189.22.155:5000

I can now access my app now at http://206.189.22.155:8080. But now in this url, instead of using the portnumber (8080) ,i want to access my app using a made up path name like /ProcessDesigner.ie,the app should be reachable at http://206.189.22.155/ProcessDesigner.

What i have tried so far

frontend http-in
    mode    http

    bind *:8080

    acl path-page-designer              path_beg -i /ProcessDesigner
    use_backend page-designer-backend   if path-page-designer

backend page-designer-backend
    mode    http

    option  httplog
    option  forwardfor
    http-request set-path /ProcessDesigner


    server  appserver1 206.189.22.155:5000

when I hit http://206.189.22.155/ProcessDesigner it says the site cannot be reached. I am doing this so that the user doesn't have to remember the port number and can just access using the pathname. So for this how should i change my configuration.Plz help by showing an example using my config!!

UPDATE using http to https redirection(80->443) and reqrep in the backend.


frontend http-in
    mode    http

    bind *:80
    bind *:443 ssl crt /etc/ssl/private/mydomain.pem
    http-request redirect scheme https code 301 if !{ ssl_fc }

    acl path-employeeList              path_beg -i /ProcessDesigner
    use_backend employeeList-backend   if path-employeeList


backend employeeList-backend
    mode    http

    option  httplog
    option  forwardfor
    reqrep  ^([^\ :]+)\ /ProcessDesigner/?(.*)$  \1\ /\2

    server  appserver1 206.189.22.155:5000

Now with this updated configuration when i hit https://206.189.22.155/ it says 503 service unavailable ( No server is available to handle this request.) and when i hit https://206.189.22.155/ProcessDesigner I dont see any errors anymore but just a blank white page.Although I can see the tab name "sample" which indicates or atleast seems as if it has reached the application , there is no output but just a blank white screen.

1 Answers1

0

What I can see in Your "what I have tried" example: You still bind to Port 8080 instead of just 80 so the site cannot be reached.

In addition the following line is probably not what You want.

http-request set-path /ProcessDesigner

It causes the request always to the backend to be always /ProcessDesigner, possibly with a query string appended.

I can imagine You need a line like the following instead to strip the /ProcessDesigner from the URI sent to backend:

reqrep  ^([^\ :]+)\ /ProcessDesigner/?(.*)$  \1\ /\2

But keep in mind the application should be properly designed to only deliver relative paths for application-local ressources within the response body (or need at least to be configurable that You can set the base path for such paths).
And it might be necessary to also rewrite the response Headers like location for redirects and set-cookie for cookies (further well-known but less common headers where this would apply are uri and content-location) as ideally the application does not need to know the URL prefix the client used for access but the cookie must be marked with the path the browser accesses the site (the rsprep exists to do such things on the response headers).

EOhm
  • 815
  • 3
  • 7
  • /ProcessDesigner is just a made up name.Its like an alias that i want to use to reach my app without having to specify the port number 8080 – Swetha Swaminathan Oct 08 '19 at 05:33
  • and also where exactly should i add the line reqrep ^([^\ :]+)\ /ProcessDesigner/?(.*)$ \1\ /\2 – Swetha Swaminathan Oct 08 '19 at 05:57
  • Yes I understand. So did You try with my suggestions? So changing listening port, removing the line I told You, possibly add the other line instead? I suggest exchanging the reqrep line for the http-request set-path line. With the result one can check which further steps are required to make it work, if any. – EOhm Oct 08 '19 at 06:01
  • hi i tried what you said...I have posted an update section in my question.Can you please check the same – Swetha Swaminathan Oct 08 '19 at 07:32
  • @SwethaSwaminathan yes I think some more work is needed then. can you please check from browser developer console what is going wrong? I cannot say this way I would need to know exactl design of the webapp. You will probably see at least one failing load in developer console network monitoring tab. – EOhm Oct 08 '19 at 08:32
  • hi i fixed the issue...i had an acl for /ProcessDesigner but not / in the frontend.Its working but what if I have multiple application running at the same time that has to be mapped through haproxy?can i bind to port 80 for all these applications? – Swetha Swaminathan Oct 08 '19 at 08:52
  • For example this app is running on port 5000...but in the future i will have few more application running on diffrent ports like 30000,8080,8000 etc.So in that case will using bind *:80 in the frontend work for all the apps running at the same time? – Swetha Swaminathan Oct 08 '19 at 08:55
  • Yes exactly that is the problem and Your fix is not a proper fix. You don't want an acl for / for forwarding to this backend. So You need to figure at wich place the appliation at Port 5000 send links to other ressourcres of the app. If it is in request body, You need to fix the application (always use only relative links to ressources within same app - or a configurable base path). If it is just in the headers You can fix the issue with rsprep. So what do You found is failing if You do not have the wrong acl for /? And where get the browser the link to that ressorce from? – EOhm Oct 08 '19 at 11:45
  • but here the pathname /ProcessDesigner is just an alias(made-up name).It is not a resource within the application that i am trying to reach. – Swetha Swaminathan Oct 08 '19 at 11:57
  • I have anyways fixed the issue and iam able to access my node.js application at https://206.189.22.155/ProcessDesigner – Swetha Swaminathan Oct 08 '19 at 12:01
  • But i am facing an issue when using multiple backends ,ie if there are 2 diffrent applications running simultaneously – Swetha Swaminathan Oct 08 '19 at 12:04
  • i have posted a new question for that at https://serverfault.com/questions/987177/unable-to-achieve-http-to-https-redirection-when-using-mutliple-backends-in-hapr – Swetha Swaminathan Oct 08 '19 at 12:04
  • I will be obliged if you can answer it there!! – Swetha Swaminathan Oct 08 '19 at 12:07
  • you did not fix the issue. what You did is exatly the same as when You remove all the config from haproxy that deals with /ProcessDesigner. and because You did not fix you of course are faing the issues. – EOhm Oct 08 '19 at 12:12