AJP doesnt work with server alias

940 Views Asked by At

I have a application which has apache and tomcat configured using mod_proxy_ajp We have configured it in httpd.conf as below:

# This is to redirect any request which is coming with hostname to   Login.jsp
RewriteRule ^/$ /jsp/Login.jsp [R]

#include httpd-proxy.conf
<IfModule mod_proxy_ajp.c>
 Include conf/extra/httpd-proxy.conf
</IfModule>

Into httpd-proxy.conf following is the proxy configuration:

<Proxy *>
  AddDefaultCharset Off
  Order deny,allow
  Allow from all
</Proxy>
ProxyPass /jsp/ ajp://localhost:8009/jsp/
ProxyPassReverse /jsp/ ajp://localhost:8009/jsp/

in server.xml file for tomcat we have configured AJP connector as below:

 <Connector port="8009" protocol="org.apache.coyote.ajp.AjpProtocol" redirectPort="8443" address="localhost" 
        enableLookups="true" maxThreads="500" connectionTimeout="120000" URIEncoding="UTF-8" />

Now when i access my machine with host name and ip address the request works fine and Login.jsp is displayed. However if i add an entry into hosts file on both server as well as client(from where browser is running) with some alias to original server name as below then it doesn't work.

    some_ip_address original_host_name  alias1 #This is alias

The request is redirected to Login.jsp when I make request as http://alias1 but the page is not coming up. In browser i can see the url as http://alias1/jsp/Login.jsp but page is not coming up. In apache ajp logs I can see response code is 200. So not sure where exactly is the problem Can anybody please help me

1

There are 1 best solutions below

0
On

I am assuming that you have used the normal mod_proxy before trying ajp, if not you should try that.

Here is an example code for adding a Virtual Host that will serve pages from Apache for the same domain and port and will redirect to a Tomcat instance for a specific Alias

<VirtualHost *:80>

    ServerName localhost
    DocumentRoot "d:/apache_test/htdocs/webapp"
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass /tomcatapp http://localhost:8080/tomcatapp
    ProxyPassReverse /tomcatapp http://localhost:8080/tomcatapp

</VirtualHost>

Using this the actual URL at the top won't change to that with Tomcat's port, but your requests will be forwarded. If required add URL mapping for specific /path in your web.xml also to further segregate requests.