Haproxy remove port number from URL












1















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(/.*)?$ /login1 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?










share|improve this question























  • First things, first... HAProxy isn't putting the port number in the URL. If you can fix this via configuration of the actual system behind HAProxy, that's almost certainly the correct fix.

    – Michael - sqlbot
    Nov 21 '18 at 21:18











  • Otherwise, you might consider trying something along the lines of http-response set-header location %[res.hdr(location),regsub(:9080/,/)] if { res.hdr(location) -m found }.

    – Michael - sqlbot
    Nov 21 '18 at 21:24
















1















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(/.*)?$ /login1 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?










share|improve this question























  • First things, first... HAProxy isn't putting the port number in the URL. If you can fix this via configuration of the actual system behind HAProxy, that's almost certainly the correct fix.

    – Michael - sqlbot
    Nov 21 '18 at 21:18











  • Otherwise, you might consider trying something along the lines of http-response set-header location %[res.hdr(location),regsub(:9080/,/)] if { res.hdr(location) -m found }.

    – Michael - sqlbot
    Nov 21 '18 at 21:24














1












1








1


1






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(/.*)?$ /login1 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?










share|improve this question














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(/.*)?$ /login1 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?







url url-rewriting haproxy






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 17:58









ViniVini

1,05421847




1,05421847













  • First things, first... HAProxy isn't putting the port number in the URL. If you can fix this via configuration of the actual system behind HAProxy, that's almost certainly the correct fix.

    – Michael - sqlbot
    Nov 21 '18 at 21:18











  • Otherwise, you might consider trying something along the lines of http-response set-header location %[res.hdr(location),regsub(:9080/,/)] if { res.hdr(location) -m found }.

    – Michael - sqlbot
    Nov 21 '18 at 21:24



















  • First things, first... HAProxy isn't putting the port number in the URL. If you can fix this via configuration of the actual system behind HAProxy, that's almost certainly the correct fix.

    – Michael - sqlbot
    Nov 21 '18 at 21:18











  • Otherwise, you might consider trying something along the lines of http-response set-header location %[res.hdr(location),regsub(:9080/,/)] if { res.hdr(location) -m found }.

    – Michael - sqlbot
    Nov 21 '18 at 21:24

















First things, first... HAProxy isn't putting the port number in the URL. If you can fix this via configuration of the actual system behind HAProxy, that's almost certainly the correct fix.

– Michael - sqlbot
Nov 21 '18 at 21:18





First things, first... HAProxy isn't putting the port number in the URL. If you can fix this via configuration of the actual system behind HAProxy, that's almost certainly the correct fix.

– Michael - sqlbot
Nov 21 '18 at 21:18













Otherwise, you might consider trying something along the lines of http-response set-header location %[res.hdr(location),regsub(:9080/,/)] if { res.hdr(location) -m found }.

– Michael - sqlbot
Nov 21 '18 at 21:24





Otherwise, you might consider trying something along the lines of http-response set-header location %[res.hdr(location),regsub(:9080/,/)] if { res.hdr(location) -m found }.

– Michael - sqlbot
Nov 21 '18 at 21:24












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418024%2fhaproxy-remove-port-number-from-url%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418024%2fhaproxy-remove-port-number-from-url%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents