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?
url url-rewriting haproxy
add a comment |
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?
url url-rewriting haproxy
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 ofhttp-response set-header location %[res.hdr(location),regsub(:9080/,/)] if { res.hdr(location) -m found }
.
– Michael - sqlbot
2 days ago
add a comment |
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?
url url-rewriting haproxy
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
url url-rewriting haproxy
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 ofhttp-response set-header location %[res.hdr(location),regsub(:9080/,/)] if { res.hdr(location) -m found }
.
– Michael - sqlbot
2 days ago
add a comment |
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 ofhttp-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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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