0

I have just set up an Ubuntu server with Tomcat7 and Apache2.

Apache is running on port 80, Tomcat on port 8080. What I want to do now is to redirect certain subdomains to Tomcat.

      mydomain.com  =>  Apache root
  www.mydomain.com  =>  Apache root
   wp.mydomain.com  =>  Apache folder Wordpress

admin.mydomain.com  =>  Tomcat project AdminTool
  api.mydomain.com  =>  Tomcat project WebService

The user should not have to enter / should not see any port numbers (just admin.mydomain.com not admin.mydomain.com:8080) when interacting with the websites.

I am aware that there are a couple of questions asking for similar things and I have also read some keywords which seam to be important for my problem (Virtual host, Proxy, ...) but this is the first time I am working with Linux and those other questions are just not detailed enough for me to understand how these things work.

Thank you!

Rico Ocepek
  • 103
  • 5

1 Answers1

0

You need to create a virtual host for each of the locations you want to have respond to different names (admin, wp, api). "www" and mydomain.com should use the default config, just make sure you have a CN record pointing for www pointing at the host.

The wp.mydomain.com virtual host is almost as easy, just change it's "Location".

For admin & API to get tomcat install mod_proxy and configure the vhost something like below for admin:

   # mod_proxy setup.
   ProxyRequests Off
   ProxyPass /webapps http://localhost:8080
   ProxyPassReverse /webapps http://localhost:8080

   <Location "/webapps/admin">
     Order allow,deny
     Allow from all
   </Location>
TheFiddlerWins
  • 2,999
  • 1
  • 15
  • 22
  • Thank you! Just a couple more questions: Do I have to open the 8080 port? If I understand it right all requests use port 80 and are just "redirected" internally. So from my understanding 8080 can remain closed in my firewall. Am I right? – Rico Ocepek Sep 22 '15 at 20:10
  • You only have to have 8080 listening on the loopback/localhost. If you can curl localhost:8080 on the server you are set. – TheFiddlerWins Sep 22 '15 at 20:11
  • I've read some tutorials for creating virtual hosts now but it still seems impossible to set this up correctly with my level of knowledge.. – Rico Ocepek Sep 22 '15 at 20:34
  • Where do I create those virtual hosts? Is it in a apache config file or is it some system config file? – Rico Ocepek Sep 25 '15 at 11:52
  • Yes, apache config file, generally you want to create them (depending on your OS) /etc/apache2/sites-available and then link them to /etc/apache2/sites-enabled – TheFiddlerWins Sep 25 '15 at 14:02
  • I need the url "example.com/webapps", i did the config and showed apache error: The requested URL was not found on this server. – Taciano Morais Silva Mar 09 '20 at 22:53