2

I am running php5, apache 2.2 and tomcat7 on ubuntu 12.10 all installed by apt-get.

I need to run both .php and .jsp files. I can run them separately on each each (tomcat and apache httpd)

I have search google but can't find a comprehensive and understandable solution for the above said versions.

Friends tell me I need a proxy (user first hits apache httpd and it forwards to tomcat if its a .jsp, then back to apache and then to the user. php is served by apache in the normal way)

1. what modules do I need? 2. what settings (*ALL) like proxy (many iam not aware of), virtual host for multiple sites do i need for both tomcat and apache.*

I think there a lack of specific guides on google or forums itself.

research:

mod_proxy_ajp replaces mod_jk

mod_php is dead

mod_php for legacy systems, fcgid for 2.2, and proxy_fcgi for 2.4

edit:

1 and 2 solved. 3 is left

I have the following vhost file below. but i have already tomcate running on 8080 for aplpinema "ROOT.war" in /home/ubuntu/tomcat/www/alpinemadotcom (which is not extracted in webapps folder but in cache folder (despite auto deploy:true)

3-. where and how do I put similer of this:

ProxyPass /apps/jira ajp://backend.example.com:8009/jira
ProxyPassReverse /apps/jira http://www.example.com/jira



<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName  www.alpinema.com
        ServerAlias alpinema.com

        DocumentRoot /home/ubuntu/apache/www/alpinemadotcom
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /home/ubuntu/apache/www/alpinemadotcom/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

1 Answer 1

2

I've done similar items to this quite frequently. There is no longer a need for mod_jk as mod_proxy_ajp replaces it as you already mentioned.

First things first, get your application fully up and running as a LAMP stack first, so all your PHP is working correctly. Once that is done there are 2 modules that you would need to make the rest work correctly mod_proxy and mod_proxy_ajp!

Add them to your LoadModule list and then you can create an alias of sorts for your vhost

Something along the lines of:

ProxyPass /apps/jira ajp://backend.example.com:8009/jira
ProxyPassReverse /apps/jira http://www.example.com/jira 

By having your apache setup for php first, everything should work normally, however once someone enters the path of http://www.example.com/jira/* then it automatically proxies through to your tomcat server. The ProxyPassReverse is useful for rewriting urls etc that the backend tomcat server sends to be more relative to your actual hosted location.

One thing that is extremely important to keep in mind is that you will need to secure your apache before you even think about using the proxy module. As an open proxy on the internet can be a very bad thing!

See this page: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#access

That same page also explains more about all the different modifications you could do with proxy module.

========= Updated Example =========

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.alpinema.com
    ServerAlias alpinema.com
    DocumentRoot /home/ubuntu/apache/www/alpinemadotcom

    ProxyPass /alpinemadotcom http://www.alpinema.com:8080/
    ProxyPassReverse /alpinemadotcom http://www.alpinema.com/alpinemadotcom 

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /home/ubuntu/apache/www/alpinemadotcom/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
8
  • PS: I work almost exclusively on redhat servers but I believe you need to apenmod proxy and proxy_ajp on ubuntu servers, I'm not 100% sure what the command is but I'm pretty sure it's not there by default.
    – Will H
    Commented Feb 20, 2013 at 22:32
  • are you sure i need mod_proxy and mod_proxy_ajp! both? and i dont have mod_proxy in /etc/apache2/mods-available$
    – kevin
    Commented Feb 20, 2013 at 22:36
  • Yes you do need both. mod_proxy_ajp depends on mod_proxy. Most of my apache servers I compile manually with dynamic linked modules. And adding mod_proxy as a module is an additional switch, so I imagine it would be the same thing in a distro installer like apt-get. Do a search to see if you can find something about it with: apt-cache search httpd or apt-cache search apache. It may be a module that needs to be installed in addition to the standard install.
    – Will H
    Commented Feb 20, 2013 at 22:41
  • and can you explain or point me to, the mechanism of what redirects what (in addition to the ProxyPass and ProxyPassReverse code you gave) , theres webapps folder and apache doc root.
    – kevin
    Commented Feb 21, 2013 at 13:31
  • got the mods. its proxy_ajp and proxy.load . what about configs?
    – kevin
    Commented Feb 21, 2013 at 14:29

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.