I've been given some source code for a PHP project that includes a .jsp file. I am able to run it as-is on my XAMPP set up on my Mac at work but I'm struggling to achieve the same on my Ubuntu setup at home.
What I need is be able to drop .jsp files in my Apache server root (/var/www/html/) and have Apache make whatever connections are necessary with Tomcat to parse the .jsp files and let Apache handle everything else.
I do not want to have to put my .jsp files or anything else in the Tomcat server root directory, I simply want Tomcat to parse the .jsp files in my Apache server root.
I've read through several articles and Questions on Stack Exchange and have achieved the following: localhost/something/something.jsp
(located in /var/www/html/something/something.jsp
) is served by Apache, and the Java code is served to the client unparsed, while navigating to localhost/something/something.php
(located next to something.jsp) shows the default "It works!" landing page for Tomcat. This is not what I wanted.
Here is my 000-default.conf file that has the proxy set up:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ProxyRequests off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass *.jsp ajp://127.0.0.1:8009/
ProxyPassReverse *.jsp ajp://127.0.0.1:8009/
<Directory "/var/www/html">
AllowOverride All
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
How can I achieve the desired result?
ProxyPass
cannot be used like that. It's more like aLocation
, forcing that a certain path (and everything under it) must be directed to a remote server. An extension should be matched withProxyPassMatch
:Also, you need no
proxy_http_module
, butproxy_ajp_module
insteadEDIT, you need a tomcat listening on port 8009 with the jsp in its root directory (which could be the same as your apache root directory) in order to "parse" the jsp, there is no way for an apache to use a application server's engine on it's own neither a tomcat to serve a page that is not under it.