Score:0

Apache Proxypass redirects "localhost:port" as url string instead of local service of the port

cz flag

Environment

Server version: Apache/2.4.6 (CentOS)


I have two servers which are almost duplicates.

aaa.com. and bbb.com.

They have almost same Apache rulesets.

aaa.com. config

<Location "/serviceEndpoint/">
  ProxyPass http://localhost:8100/serviceEndpoint/
  ProxyPassReverse http://localhost:8100/serviceEndpoint/
</Location>
<Location "/fruit/apple">
  ProxyPass "/fruit/apple" "http://localhost:8100/serviceEndpoint/fruit/apple"
  ProxyPassReverse "/fruit/apple" "http://localhost:8100/serviceEndpoint/fruit/apple"
</Location>

So /serviceEndpoint is a service using 8100 port, and /fruit/apple is a servlet of it.

bbb.com. config

<VirtualHost _default_:80>
  ProxyPass "/serviceEndpoint/" "http://localhost:20100/serviceEndpoint/"
  ProxyPassReverse "/serviceEndpoint/" "http://localhost:20100/serviceEndpoint/"

  ProxyPass "/fruit/apple" "http://localhost:20100/serviceEndpoint/fruit/apple"
  ProxyPassReverse "/fruit/apple" "http://localhost:20100/serviceEndpoint/fruit/apple"
</VirtualHost>

Looks the same, but it's inside VirtualHost:80, if that makes anything different.
(*edit I tested using the same config, but the result was same)

Problem

Both aaa.com/fruit/apple or bbb.com/fruit/apple works well.

But, when the service use response.sendRedirect()(java) and redirects the browser to /fruit/apple,
only aaa.com. works and bbb.com. tries to connect literal http://localhost:20100/fruit/apple from the client browser.

aaa.com redirect response header

HTTP/1.1 302
Date: Mon, 09 May 2022 08:01:29 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=63072000; includeSubDomains
Location: /fruit/#!/some_controller
Content-Length: 0
Set-Cookie: JSESSIONID=4EA61F0E6031621E540DBDC9F6C54D64; Path=/serviceEndpoint; HttpOnly
Set-Cookie: JSESSIONID=4EA61F0E6031621E540DBDC9F6C54D64; Secure; HttpOnly; SameSite=Strict
X-XSS-Protection: 1; mode=block
Keep-Alive: timeout=15, max=95
Connection: Keep-Alive

bbb.com redirect response header

HTTP/1.1 302
Date: Mon, 09 May 2022 08:01:29 GMT
Server: Apache-Coyote/1.1
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=63072000; includeSubDomains
Location: http://localhost:20100/fruit/#!/some_controller
Content-Length: 0
Set-Cookie: JSESSIONID=4EA61F0E6031621E540DBDC9F6C54D64; Path=/serviceEndpoint; HttpOnly
Set-Cookie: JSESSIONID=4EA61F0E6031621E540DBDC9F6C54D64; Secure; HttpOnly; SameSite=Strict
Keep-Alive: timeout=15, max=95
Connection: Keep-Alive

Question

From Apache settings, what can cause this behavior and how should I fix this?

in flag
The redirect does not come from Apache. Configure your Backend service with the proper URL to redirect to.
Lunartist avatar
cz flag
@GeraldSchneider The redirect path is `/fruit/apple` and service works fine with `aaa.com.` What could causes this discrepancy?
Lunartist avatar
cz flag
@GeraldSchneider `aaa.com` operates on Tomcat 8.5, and `bbb.com` operates on Tomcat 8.0. Would it affect how `response.sendRedirect()` behave?
Score:0
cz flag

It was Tomcat difference. Tomcat 8.0 redirects to localhost, whereas 8.5 redirects normally.

Score:0
us flag
Rob

That ProxyPassReverse directive defines the scope of the URL path(s) that Apache most correct for in back-end responses to ensure that site vistors are presented with a correct URL that matches their requests to the Apache

ProxyPassReverse "/fruit/apple" "http://localhost:20100/serviceEndpoint/fruit/apple"

The bbb.example.com response redirects to

 Location: http://localhost:20100/fruit/#!/some_controller
                                       \
                                        `- "apple" is missing . 

and therefor the Location header is not corrected for by the ProxyPassReverse directive.

That seems like either the back-end application does not create correct self-referential URL's and you need to solve that in the back-end application, or you have made an incorrect assumption and your apache config should be:

ProxyPass "/fruit/" "http://localhost:20100/serviceEndpoint/fruit/"
ProxyPassReverse "/fruit/" "http://localhost:20100/serviceEndpoint/fruit/"
Lunartist avatar
cz flag
`aaa.com.` redirects normally to `https://aaa.com/apple/#!/some_controller`. What could make this difference?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.