Categories
Java Plesk Technology Tomcat

Tomcat webapps and a Plesk vhost.conf file

Plesk loves to overwrite all manual changes to the httpd.include file for your vhost. In fact, this is the normal behavior of Plesk, and you must place all changes in a separate file, vhost.conf (notice the warning inside of httpd.include)


# ATTENTION!
# DO NOT MODIFY THIS FILE OR ANY PART OF IT. THIS CAN RESULT IN IMPROPER PLESK
# FUNCTIONING OR FAILURE, CAUSE DAMAGE AND LOSS OF DATA. IF YOU REQUIRE CUSTOM
# MODIFICATIONS TO BE APPLIED TO THE CONFIGURATION, PLEASE, PERFORM THEM IN THE
# FOLLOWING FILE(S):
# /home/httpd/vhosts/europheus.com/conf/vhost.conf
# /home/httpd/vhosts/europheus.com/conf/vhost_ssl.conf

The following is an example vhosts.conf file. As you can see from this example, you can override everything inside of the <VirtualHost> block.


DocumentRoot /home/httpd/vhosts/domain.com/webapps/ROOT

<Directory "/home/httpd/vhosts/domain.com/webapps/ROOT">
 Options Indexes FollowSymLinks
 DirectoryIndex index.jsp index.html index.htm
</Directory>

JkMount /servlet/* ajp13
JkMount /*.jsp ajp13

<Location "/WEB-INF/*">
 AllowOverride None
 deny from all
</Location>
<Location "/META-INF/*">
 AllowOverride None
 deny from all
</Location>

Once you have added the vhosts.conf file you may also want to create an exact copy called vhosts_ssl.conf

Next, you need to inform Plesk of your changes, and Plesk will update the httpd.include file to include your vhosts file.

/usr/local/psa/admin/sbin/websrvmng -u –vhost-name=domain.com

You should not need to restart Apache, however if your changes are not available, try restarting Apache.

About the example:

This example expects the mod_jk module installed to connect Apache with Tomcat. It also expects a webapps and ROOT folder under the vhost’s main folder. The details of these configurations will be explained in another article.

The following line will ignore your vhost’s httpdocs folder and redirect all requests to the webapps/ROOT folder. This configuration allows Tomcat to serve your .jsp files, and have Apache serve all other files such as images. Apache is faster than Tomcat at serving images and other binary files.

DocumentRoot /home/httpd/vhosts/domain.com/webapps/ROOT

You can include subfolders in your vhost’s httpdocs folder if you would like to serve various PHP apps along with your java webapp.

Alias /forum /home/httpd/vhosts/domain.com/httpdocs/phpBB

The following line will allow your index.jsp to appear as by default. When you type in www.domain.com, the index.jsp should appear.

DirectoryIndex index.jsp index.html index.htm

The following tells Apache to ignore (do not serve files) from the specified folders. This keeps your configuration files (web.xml) safe from being served to a client.


<Location "/WEB-INF/*">
 AllowOverride None
 deny from all
</Location>
<Location "/META-INF/*">
 AllowOverride None
 deny from all
</Location>

Running Tomcat on Plesk is a pain, and out of the box, its near useless. You may find yourself making numerous modifications to the configuration. Stay tuned to this blog for more examples of how to force happiness with Plesk and Tomcat.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.