0

Firstly, excused me for my english. I have a doubt, Can I have a LAMP with a wordpress installation with domain name "domain1.es" and also have in the same host a tomcat running a servlet with a domain name "domain2.es"?

Now, I have this installation but in conflict. My tomcat is in "domain2.es:8080" and my wordpress is in "domain1.es". When I enter to "domain2.es" without the port 8080 it shows the wordpress due to the DNS.

How can I resolve this?

Thank you.

1 Answers1

2

You will need to configure two virtual host entries in Apache httpd, one for your existing WordPress site (that may already exist) and second one for the Tomcat domain.

You can configure a simple redirect that will direct all vistors that omitted port 8080 from the URL to try and connect to the correct port:

<VirtualHost *:80>
    ServerName  www.example.es
    ServerAlias example.es
    ... 
</VirtualHost>
<VirtualHost *:80>
    ServerName  www.example.com
    ServerAlias example.com
    # Redirect the visitor to the correct port. 
    # The URL in the visitors browsers will change

    Redirect / http://www.example.com:8080/

</VirtualHost>

Alternatively configure Apache to reverse proxy the requests to Tomcat:

<VirtualHost *:80>
    ServerName  www.example.com
    ServerAlias example.com

    # Reverse Proxy the requests to port 8080. 
    # The URL in the visitors browsers will NOT change 
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>

The looks better as the URL won't include a non-standard port anymore, but still has a couple of disadvantages. (For instance Tomcat will no longer detect the IP-addresses of your visitors, all requests will appear to originate from your own IP.)

A much better option is to configure the AJP protocol and mod_jk but that takes a little more than a simple Q&A to explain.

HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • I need the url "example.com/webapps", i did: ProxyPass /webapps http://localhost:8080/ and ProxyPassReverse /webapps http://localhost:8080/ Order allow,deny Allow from all / Apache error: The requested URL was not found on this server. – Taciano Morais Silva Mar 09 '20 at 22:50