I have configured my web application using Apache-Tomcat connector through mod_proxy - see below.
<IfModule mod_proxy.c>
ProxyPass /myapp http://127.0.0.1:8080/myapp
ProxyPassReverse /myapp http://127.0.0.1:8080/myapp
</IfModule>
Also, I am using sub-domains in order to identify the clients directly by reading the URL - see below for the example.
Client1 types
http://client1.mydomain.com/myapp
Client2 types
http://client2.mydomain.com/myapp
Now, I want to read the URL and parse the client name (client1 or client2). The rest of my web application is driven based on who the client is (of course, after authentication). But the issue is, when I try to get URL using HttpServletRequest's getRequestURL, I get http://127.0.0.1:8080/myapp instead of client1.mydomain or client2.mydomain. This, I suppose, is due to Apache being used as the primary dispatcher and the request to Apache httpd is being forwarded to localhost Tomcat.
I don't want to change the structure of URL (like client1.mydomain.com/client1) nor do I want to ask user for th开发者_运维技巧e client information through UI. How do I achieve this?
I solved this problem by using AJP connector instead of mod_proxy.
<Location /myapp>
ProxyPass ajp://localhost:8009/myapp
ProxyPassReverse ajp://localhost:8009/myapp
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
</Location>
AJP connector forwarded the request from apache to tomcat preserving the browser URL (while mod_proxy changed it to localhost:8080/myapp) and hence I was able to read and parse the client name from it.
Now I can render client-specific data without actually prompting the user for his/her client name.
精彩评论