Can a single Apache server handle both Tomcat and PHP?

后端 未结 4 791
滥情空心
滥情空心 2021-02-04 15:26

I have a requirement as to have a single server with both a Java application and a PHP application, running on the same Apache. Is this possible?

This question may be ve

相关标签:
4条回答
  • 2021-02-04 15:44

    Can a sinle apache server handle both tomcat and php?

    Yes, you need both apache and tomcat installed, but you can configure apache to redirect (transparently for the user) all JSP requests to tomcat using AJP protocol.

    See more here: http://www.datadisk.co.uk/html_docs/java_app/tomcat6/tomcat6_apache_server.htm

    0 讨论(0)
  • 2021-02-04 15:45

    Yes you can do that. Essentially you have to run the Apache (+ PHP) server on one port and the Tomcat server on a different port.

    • You can expose the 2nd port to the outside world, and have your URLs use either port 80 for Apache / PHP or (say) 8080 for the Java server. This simple, but you may find that upstream firewalls prevent a remote web browser from connecting to any port other than 80.

    • You can configure your Apache server as a reverse proxy for the Java server. So for instance, the Apache server might recognize that http://site.com/javaapp/foo.html is for the Java server, and relay requests for that URL to http://localhost:8080/javaapp/foo.html.

    There is a whole chapter of the Apache documentation about configuring forward and reverse proxies using mod_proxy.

    0 讨论(0)
  • 2021-02-04 15:54

    This is possible using Apache Reverse Proxy,

    I configured one Apache virtual host that serves one PHP website (Drupal) and one java (tomcat, for business logic) that are stored in the same server using a reverse proxy with 2 locations, the advantage of this configuration is that it doesn't expose the port that Tomcat is using on the URL which was mandatory for me for security reasons.

    This is how I achieved this:

    <VirtualHost *:80>
    ProxyPreserveHost       On
    DocumentRoot            "/srv/www/htdocs/"
    ErrorLog                /var/log/httpd/app_error_log.log
    CustomLog               /var/log/httpd/app_log.log combined
    ServerName              myapp.com
    
    #Drupal PHP Content, stored at / as the main front end website.
    <Location />
        ProxyPass http://localhost/
        ProxyPassReverse http://localhost
        Order allow,deny
        Allow from all
    </Location>
    
    #Tomcat/java content, secondary site used to process payments and business logic:
    <Location /javaApp>
        ProxyPass http://localhost:8080/javaApp/
        ProxyPassReverse http://localhost:8080/javaApp/
        Order allow,deny
        Allow from all
    </Location>
    
    </VirtualHost>
    

    Restart Apache:

    service httpd restart;
    

    Test your reverse proxies: PHP/Drupal (In my case i'm using drupal but can be any PHP code):

    http://yourserverip/ or http://localhost/
    

    Java:

    http://yourserverip/javaApp or http://localhost/javaApp
    

    I hope someone can find this useful. I had a hard time trying to figure this out. :)

    Regards.

    0 讨论(0)
  • 2021-02-04 16:07

    Yes.

    Apache HTTPd can delegate to Apache Tomcat using ModProxy or ModAJP, and can be configured to do so based on the domain, path or file extension requested. Your Apache HTTPd configuration of PHP would remain the same.

    You would need to configure Apache Tomcat to not listen on port 80, and then configure the Apache HTTPd proxying solution of your choice to talk to Tomcat on a different port.

    Here's a starting point for more information: Apache + Tomcat: Using mod_proxy instead of AJP

    0 讨论(0)
提交回复
热议问题