Haproxy remove port number from URL











up vote
0
down vote

favorite












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
    2 days ago










  • 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
    2 days ago















up vote
0
down vote

favorite












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
    2 days ago










  • 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
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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 2 days ago









Vini

1,03021743




1,03021743












  • 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
    2 days ago










  • 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
    2 days ago


















  • 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
    2 days ago










  • 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
    2 days ago
















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
2 days ago




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
2 days ago












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
2 days ago




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
2 days ago

















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',
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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


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

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu