4

I currently have a tomcat servlet 1 running under the ROOT:

api1.myhost.com:8080/

I'm using mod_proxy and simply forwarding all requests from api1.myhost.com to this instance. This is working as of today.

I now have installed a second servlet 2 which runs under the same instance of tomcat (same IP address):

www.myhost.com:8080/servlet2

I want all requests to a new URL api2 to go to that second servlet such that:

api2.myhost.com

now gets forwarded to the second servlet instance.

I've created an A record such that api2.myhost.com points to my server IP. How do you make api2.myhost.com forward to www.myhost.com:8080/servlet2 ?

1 Answer 1

3

You need to make two VirtualHost's with on pointing to the first webapp, the other to the second.

<VirtualHost *:80>
    ServerName api1.myhost.com
    ProxyPass / http://api1.myhost.com:8080/
    ProxyPassReverse / http://api1.myhost.com:8080/
</VirtualHost>

<VirtualHost *:80>
        ServerName api2.myhost.com
        ProxyPass / http://www.myhost.com:8080/servlet2
        ProxyPassReverse / http://www.myhost.com:8080/servlet2
</VirtualHost>

Note that since the path will be different on tomcat than on apache, you will need to use relative URLs in your application.

Sign up to request clarification or add additional context in comments.

3 Comments

awesome this worked with one minor correction. I had to have the following line also: NameVirtualHost *:80
what file do we add these virtualhost records to?
Any file that is included in the main apache conf file. There is often a separate file for each virtual host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.