Haproxy remove port number from URL

我的梦境 提交于 2019-12-08 04:05:48

问题


I have a backend trying to route traffic to a specific IP address and a port. The first hit on the url doesn't contain the port number. But the subsequesnt requests from within the website is not redirected properly.

Example: http://test.com has server 123.45.67.89:9080

When I try the URL http://test.com/login --> It is redirected correctly and I get the login page.

But once I give the login details and press OK. It is redirected to http://test.com:9080/loginSuccess.

The page is available under http://test.com/loginsuccess

This is the backend code and all the ways I have tried from different solution is commented.

backend lf_was_9080
   acl auth_lf_was http_auth(lf_was_auth_list)
   http-request auth realm lf_was_auth_list if !auth_lf_was
   mode http

   #TRY 1
   #http-request redirect prefix http://test.com/login if { hdr(host) -i test.com:9080/login }

   #TRY 2
   # Clean the request and remove any existing header named X-Rewrite
   http-request del-header X-REWRITE

   # Copy the full request URL into X-Rewrite unchanged
   http-request add-header X-REWRITE %[url] if { path_sub 9080/login }

   # Change the X-REWRITE header to contain out new path
   http-request replace-header X-REWRITE ^:9080/login(/.*)?$ /login\1 if { hdr_cnt(X-REWRITE) gt 0 }

   # Perform the 301 redirect
   http-request redirect code 301 location http://%[hdr(host)]%[hdr(X-REWRITE)] if { hdr_cnt(X-REWRITE) gt 0 }

   #TRY 3
   #reqrep ^([^\ :]*)\ /login/(.*)     \1\ /login/\2

   #TRY 4
   #http-request redirect prefix https://test.com if { hdr(host) -i test.com:9080 }
  server lf_was_9080 10.85.200.158:9080 check

I have also https redirect which works perfectly.

How can i rewrite the url without the port number in Haproxy?

来源:https://stackoverflow.com/questions/53418024/haproxy-remove-port-number-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!