1

I am trying to setup a Load balancer with Apache mod_proxy and Tomcat. I have the following modules available (mod_proxy, mod_proxy_balancer, mod_proxy_http) I have 2 Tomcat instances and the plan is to route the request to one of the Tomcat server.

My application on Tomcat is running fine when I directly access. www.mydomain:8080/myapp www.mydomain:9080/myapp

My Tomcat server.xml has the following Tomcat 1 Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1"

Tomcat 2 Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2"

Here is what I have in my virtualhost.conf

<IfModule proxy_module> ProxyRequests on ProxyPreserveHost Off ProxyPass / balancer://mycluster/ stickysession=JSESSIONID ProxyPassReverse / balancer://mycluster/ stickysession=JSESSIONID ProxyPassReverseCookiePath /myapp / <Proxy balancer://mycluster > BalancerMember http://localhost:8080/myapp route=tomcat1 BalancerMember http://localhost:9080/myapp route=tomcat2 Require all granted ProxySet lbmethod=byrequests </Proxy> <Location /balancer> SetHandler balancer Require host www.mydomain.com </Location> </IfModule> 

With the above configuration I am able to access the site first page. When I access www.mydomain.com, it loads the login page(www.mydomain.com/login.do) When I click on other links it's opening the correct pages. For eg: www.mydomain.com/password-reset.do The basic fail over also works. If I shutdown one Tomcat Instances, it serves the page from the other server and vice versa.

But when I try to submit any POST requst like try to Login, the url change to www.mydomain/myapp/login.do and always shows the login page.

I am not sure the above conf entries are fully correct with respect to what I want. Can some one points me what is wrong. Also please let me know if I am lacking anything here with respect to sucurity. I also would like to have image files and other files served directly from the Webserver. Please let me know how I can do that.

Thanks

1 Answer 1

0

There are two cases when this usually happens. It doesn't involve balancer - it happens all the same with a single backend.

  1. A place in the HTML of application could contain a literal absolute URL like http://example.com/myapp/post_here so POST goes there (which in fact hits backend with http://127.0.0.1:xxxx/myapp/myapp/post_here). There is a broad range of solutions to this.

  2. Another possibility. The POST usually results in a redirect (302). The backend might redirect to an absolute URL http://example.com/myapp/post_here which wouldn't be catched. Your ProxyPassReverse presently only catches http://127.0.0.1:xxxx/myapp/post_here. You can add ProxyPassReverse / http://example.com/myapp below yours as an additional one, it's allowed.

Both cases are simple to observe if you set your browser to log network requests/responses (developer option in both Firefox and Chrome).

1
  • All URLs used are relative URL. No absolute URLs used. If I view source my login page I have the following. <form .... action="/myapp/login.do" method="post"> I tried what you mentioned, but didn't fix the issue. When I open the Dev Tools on Chrome and view traffic, I see the following Request URL: example.com/myapp/login.do Request Method: POST Status Code: 404 Not Found Referrer Policy: no-referrer-when-downgrade At the same time if I access my Tomcat directly, there is no issue. All works perfect. So I assume the issue somewhere with my proxy setting. Commented Apr 9, 2018 at 23:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.