简体   繁体   中英

Multiple sites in Apache and Tomcat servers

I have a centOS machine with Apache HTTP server running on Port 80 and Apache Tomcat running on port 8080. A PHP application is running on Http Server and a java based application running on tomcat.

I want a sub-domain to be to be mapped to the Php app and another sub-domain to be mapped to the java app.

This is the mapping that I required.

http://www.a.myDomain.com/  ---   php app  and
http://www.app.myDomain.com/ ----java pp

To achieve this, I have made the following changes in the configuration files.

httpd.conf

Added the following lines,

LoadModule negotiation_module modules/mod_negotiation.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Also, added the following

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName app.myDomain.com
    ServerAlias www.app.myDomain.com
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass /  http://localhost:8080/
    ProxyPassReverse /  http://localhost:8080/
</VirtualHost>


<VirtualHost *:80>      
    DocumentRoot /var/www/html/test/
    ServerName a.myDomain.com
    ServerAlias www.a.myDomain.com
</VirtualHost>

Tomcat - Server.xml

    <Host name="www.app.myDomain.com"  appBase="/home/centos/apache-tomcat-8.0.0-RC3/webapps/myApp"
        unpackWARs="true" autoDeploy="true"  xmlValidation="false"
          xmlNamespaceAware="false" >
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

 <Context path="" docBase="/home/centos/apache-tomcat-8.0.0-RC3/webapps/myApp"
               debug="0" reloadable="false"/>

I have modified the configuration files as above and now I can access the two applications by using the URLS

http://www.a.myDomain.com/
http://www.app.myDomain.com:8080/

This is working fine.

But I want to access the java application without specifying the port

ie, the Java app should be accessible by

 http://www.app.myDomain.com/
 instead of    http://www.app.myDomain.com:8080/

I have added the code for reverse proxy in apache conf(see the httpd conf file), but it is not working. When I am accessing the url

http://www.app.myDomain.com/

I am getting the following error

Service Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Any mistake in the Apache configuration?

It looks your httpd.conf is fine with the configuration.

In that, the proxy will redirect the request "app.myDomain.com" to "locahost:8080"

But the problem your tomcat is host on "www.app.myDomain.com"

Change the "www.app.myDomain.com" in server.xml tag to "localhost" may resolve your problem.

I found a solution.

Modified the ProxyPass and ProxyPassReverse as below

ProxyPass / ajp://localhost:8009/
ProxyPassReverse /  http://localhost:8009/

Now I can access php app by http://www.a.myDomain.com/ and Java app by http://www.app.myDomain.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM