How to set up .JSP pages to run from domain's DocumentRoot directory?

Created:

2016-11-16 13:11:45 UTC

Modified:

2017-08-22 12:27:28 UTC

2

Was this article helpful?


Have more questions?

Submit a request

How to set up .JSP pages to run from domain's DocumentRoot directory?

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux
  • Plesk 11.x for Linux

Question

How to set up .JSP pages to run from domain's DocumentRoot directory?

Answer

The following requirements should be met:

1. The JSP application should be accessible by the root domain link (by the http://example.com/ address)

2. The application must be able to save its data

3. The application must have configurable settings and code

Thus, the possible ways are as follows:

Plesk 12.5 :

  1. The first method:

A typical application with a .war format, uploaded via the Plesk interface, may meet all the requirements above. For access to the application via the "root" URL of a domain, it is possible to use the mod_rewrite module or use redirection via the index document of the site. The .war application will not be unpacked, and therefore, its files will not be alterable. However, some non-Plesk integrated solution or database may be used to save the application's data (even multimedia files).

To modify the application code, it will be necessary to reinstall the package completely (remove the old .war file and upload the new one). During the maintenance procedure, the application will be unavailable.

  1. The second method

a) Enable Tomcat in Tools & Settings > Services Management > Tomcat Java > enable . Make sure that service is running on the server using the following command:

    # service tomcat status

b) Add the tomcat system account to the psaserv group to allow the user to go through the httpdocs folder:

    # usermod -a -G psaserv tomcat

You can check that user was successfully added using:

# cat /etc/group | grep tomcat
psaserv:x:1002:psaadm,psaftp,apache,nginx,tomcat

c) Make a particular folder for the application, here is example for javaApp folder:

    # mkdir /var/www/vhosts/example.com/httpdocs/javaApp
# chown <user>:psaserv /var/www/vhosts/example.com/httpdocs/javaApp
# chmod 0750 /var/www/vhosts/example.com/httpdocs/javaApp

d) Unpack all application files in httpdocs folder. Configure all necessary permissions for the tomcat user. Here is the example for index.jsp which was placed into /var/www/vhosts/example.com/httpdocs/javaApp :

     # chown tomcat:tomcat /var/www/vhosts/example.com/httpdocs/javaApp/index.jsp
# chmod 0644 /var/www/vhosts/example.com/httpdocs/javaApp/index.jsp
# ls -la /var/www/vhosts/example.com/httpdocs/javaApp
-rw-r--r-- 1 tomcat tomcat 250 Jun 10 16:04 index.jsp

e) Forward all requests with the http://example.com/javaApp URL to Tomcat: go to Plesk > domains > example.com > Apache & Nginx Settings and paste the following into Additional directives for HTTP section:

    <IfModule mod_jk.c>
JkMount /javaApp ajp13
JkMount /javaApp/* ajp13
</IfModule>

f) Create virtual host base options in /etc/tomcat/server.xml , paste the following into it:

    <Host name="example.com" appBase="/var/www/vhosts/example.com/httpdocs" />

Make sure that it it pasted right after <Host name="localhost".... </Host> for example:

     <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<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"/>
</Host>

<Host name="example.com" appBase="/var/www/vhosts/example.com/httpdocs" />

g) Restart tomcat:

    # service tomcat restart

You can track log messages of tomcat located in /var/log/tomcat/catalina*.log in case of any issues.

h) Configure application in application config. Create javaApp.xml , where javaApp.xml - is application relative directory name defined in step (c) + .xml :

     # touch /etc/tomcat/Catalina/example.com/javaApp.xml
# chown root:tomcat /etc/tomcat/Catalina/example.com/javaApp.xml

i) Paste the following into newly created file /etc/tomcat/Catalina/example.com/javaApp.xml :

    <?xml version="1.0" encoding="utf-8"?>
<Context path="/javaApp" />

Tomcat will use a new configuration automatically. Restart tomcat service is not required.

  1. The third method

a) Enable Tomcat in Tools & Settings > Services Management > Tomcat Java > enable . Make sure that service is running on the server using the following command:

    # service tomcat status

b) Add the tomcat system account to the psaserv group to allow the user to go through the httpdocs folder:

    # usermod -a -G psaserv tomcat

You can check that user was successfully added using:

# cat /etc/group | grep tomcat
psaserv:x:1002:psaadm,psaftp,apache,nginx,tomcat

c) Unpack all application files in httpdocs folder. Configure all necessary permissions for the tomcat use. Here is the example for index.jsp which was placed into /var/www/vhosts/example.com/httpdocs/ :

     # chown tomcat:tomcat /var/www/vhosts/example.com/httpdocs/index.jsp
# chmod 0644 /var/www/vhosts/example.com/httpdocs/index.jsp
# ls -la /var/www/vhosts/example.com/httpdocs/
-rw-r--r-- 1 tomcat tomcat 250 Jun 10 16:04 index.jsp

d) Forward all requests with the http://example.com URL to Tomcat: go to Plesk > domains > example.com > Apache & Nginx Settings and paste the following into Additional directives for HTTP section:

      <IfModule mod_jk.c>
JkMount / ajp13
JkMount /* ajp13
</IfModule>

e) Create virtual host base options in /etc/tomcat/server.xml , paste the following into it:

    <Host name="example.com" appBase="/var/www/vhosts/example.com/httpdocs" />

Make sure that it it pasted right after <Host name="localhost".... </Host> for example:

     <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<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"/>
</Host>

<Host name="example.com" appBase="/var/www/vhosts/example.com/httpdocs" />

f) Restart tomcat:

    # service tomcat restart

You can track log messages of tomcat located in /var/log/tomcat/catalina*.log in case of any issues.

g) Configure application in application config. Create ROOT.xml under /etc/tomcat/Catalina/example.com/ and apply correct permissions:

    # touch /etc/tomcat/Catalina/example.com/ROOT.xml
# chown root:tomcat /etc/tomcat/Catalina/example.com/ROOT.xml

h) Paste the following into newly created file /etc/tomcat/Catalina/example.com/ROOT.xml

    <?xml version='1.0' encoding='utf-8'?>
<Context path="/" docBase="/var/www/vhosts/example.com/httpdocs/" />

Avoid any spaces in this configuration file. Then you can access your application under http://example.com Tomcat will use a new configuration automatically. Restart tomcat service is not required.

Plesk 11.5

  1. The first method:

A typical application with a .war format, uploaded via the Plesk interface, may meet all the requirements above. For access to the application via the "root" URL of a domain, it is possible to use the mod_rewrite module or use redirection via the index doc of the site. The .war application will not be unpacked, and therefore, its files will not be alterable. However, some non-PP integrated solution or database may be used to save the application's data (even multimedia files).

To modify the application code, it will be necessary to reinstall the package completely (remove the old .war file and upload the new one). During the maintenance procedure, the application will be unavailable.

  1. The second method:

a) Enable the Tomcat service for a domain via the PP web-interface.

b) Make a particular folder for the application (for example, with the "example.com" domain):

    # mkdir /var/www/vhosts/example.com/httpdocs/javaApp

c) Unpack all application files in the created folder. Configure all necessary permissions for the tomcat user (so that the user can modify the files, for example).

d) Add the tomcat system account to the psaserv group to allow the user to go through the httpdocs folder:

    # usermod -a -G psaserv tomcat

e) Modify the /var/www/vhosts/example.com/conf/vhost.conf file for forwarding all requests with the http://example.com/javaApp URL to Tomcat:

    <IfModule mod_jk.c>
JkMount /javaApp ajp13
JkMount /javaApp/* ajp13
</IfModule>

f) Add necessary mod_rewrite rules in the httpdocs/.htaccess file or in the vhost.conf one for forwarding all requests from the http://example.com/ URL to the http://example.com/javaApp one.

g) Create a context for the application in the /usr/share/tomcat5/conf/PSA/example.com/javaApp.xml file:

    <Context crossContext="false"
reloadable="false" useNaming="true" debug="0" swallowOutput="false"
privileged="true" displayName="My application"
docBase="/var/www/vhosts/example.com/httpdocs/javaApp" cookies="true"
path="/javaApp" cachingAllowed="true"/>

h) Make sure that in 'Apache&nginx settings' the default website page should be 'index.jsp' but not 'index.html'.

The context parameters should be changed according to the application requirements. The docBase and path ones are defined by the application location and website URL.

If the /usr/share/tomcat5/conf/PSA/example.com folder does not exist, then it should be created. The context file must be readable for the tomcat user.

h) Reconfigure the website and restart Tomcat service:

    # /usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=example.com
# /etc/init.d/tomcat5 restart
  1. The third method:

a) Enable the Tomcat service for the domain via the PP web-interface.

b) Unpack all application files in the httpdocs folder of the domain. Configure all necessary permissions for the tomcat user (so that the user can modify the files, for example).

c) Add the tomcat system account to the psaserv group to allow the user to go through the httpdocs folder:

    # usermod -a -G psaserv tomcat

d) Modify the /var/www/vhosts/example.com/conf/vhost.conf file for forwarding all requests with the http://example.com/ URL to Tomcat:

    <IfModule mod_jk.c>
JkMount /javaApp ajp13
JkMount /javaApp/* ajp13
</IfModule>

e) Create a context for the application in the /usr/share/tomcat5/conf/PSA/example.com/ROOT.xml file:

    <Context crossContext="false"
reloadable="false" useNaming="true" debug="0" swallowOutput="false"
privileged="true" displayName="MyApp"
docBase="/var/www/vhosts/example.com/httpdocs" cookies="true"
path="" cachingAllowed="true"/>

The parameters should be configured according to the application requirements. The docBase parameter should be equal to the httpdocs path. The path parameter value should be empty.

f) Reconfigure the website and restart Tomcat service:

    # /usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=example.com
# /etc/init.d/tomcat5 restart

Note! The second and third methods have the following weak points: It is required to have administrative access to configure context files and provide necessary permissions to the application files. The tomcat user must be added to the psaserv group, and this may cause some security issues. To avoid such issues, it is possible to configure and enable the Java-machine security features. Also, in the case of backing up Plesk sites, the custom Tomcat configuration will not be saved. It will be necessary to restore the configuration manually (including the tomcat user configuration).

Additional information

#213941805 How can I verify Tomcat service works on my Plesk?

#213364849 How to run Java applications in Plesk?

Note: While checking the issue, If you notice that mod_jk was trying to connect to port 9008.
--------------------
[root@plesk ~]# tailf /var/log/httpd/mod_jk.log
[Thu Apr 20 08:58:00.849 2017] [16675:140580705236736] [info] jk_open_socket::jk_connect.c (758): connect to 127.0.0.1:9008 failed (errno=111)
[Thu Apr 20 08:58:00.849 2017] [16675:140580705236736] [info] ajp_connect_to_endpoint::jk_ajp_common.c (1019): Failed opening socket to (127.0.0.1:9008) (errno=111)
[Thu Apr 20 08:58:00.849 2017] [16675:140580705236736] [error] ajp_send_request::jk_ajp_common.c (1663): (ajp13) connecting to backend failed. Tomcat is probably not started or is listening on the wrong port (errno=111)
[Thu Apr 20 08:58:00.849 2017] [16675:140580705236736] [info] ajp_service::jk_ajp_common.c (2673): (ajp13) sending request to tomcat failed (recoverable), because of error during request sending (attempt=1)
--------------------

And following is the connection string created while you have tried installing war file in Plesk.  But mod_jk works with different port number "8009".
--------------------
[root@plesk ~]# cat /etc/httpd/conf/workers.properties
worker.list=ajp13
worker.ajp13.port=9008
worker.ajp13.host=127.0.0.1
worker.ajp13.type=ajp13
--------------------

Then, in order to make .JSP work for the domain modify the configuration as follows:
--------------------
[root@plesk ~]# cat /etc/httpd/conf/workers.properties
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=127.0.0.1
worker.ajp13.type=ajp13
[root@plesk ~]#
--------------------

Have more questions? Submit a request
Please sign in to leave a comment.