Chia Sẽ Kinh Nghiệm Về IT



Tìm Kiếm Với Google
-


Gởi Ðề Tài Mới  Gửi trả lời
 
Công Cụ Xếp Bài
Tuổi 17-12-2010, 04:43 PM   #1
hoctinhoc
Guest
 
Trả Lời: n/a
Plesk - Tomcat - Java - JSP scripts
1. Plesk - Tomcat Installation

Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies.

Note: This article is relevant to 4t Networks VPS hosting accounts with Plesk only.

Contents

The following topics are covered in this article.
  • Installation
  • Configuration

Note: 4t Networks technicians are very fluent in Tomcat based installation, maintenance and support. If you need assistance with your Tomcat installation or application please feel free to contact support for assistance.

Tomcat Installation
Tomcat installation and setup for your Plesk domain is relatively simple and straight forward. The following instructions are based on the type of installation/setup that falls under 4T Networks support policy. You may chose to setup Tomcat any way you like however, it may not be something that we can support if these instructions are not followed.

1. 4T Networks provides a pre-packaged current release of Tomcat. You may install your own version but we may not be able to support it for you. To install Tomcat;
  1. Login to your PBA Control Panel
  2. Select the System Tab
  3. Navigate to the Applications Menu and click Add Application
  4. Select both Jdk6 and Tomcat 6 from the list of applications and click the Next Button to start the installation
Note: Installation of these applications should take one to two minutes or less.

Now you can check to make sure Tomcat is running. Visit the following URL in your web browser. http://domain.com:8080 or http://ipaddress:8080 [replace the domain/IP with your actual domain/IP]. You should see the Tomcat default index page. If you do not, make sure the very that you followed the steps above or contact support if you feel you have done so.

Tomcat Configuration
There are many methods to configure Tomcat. We will look at two of those here. These are the preferred / supported methods by 4T Networks.

Note: These examples will use [example.com] as the domain. Make sure to replace this with your actual domain name.

Example one
Serving .jsp, .war from the tomcat default webapps directory

You cannot directly FTP your .jsp to the Tomcat webapps directory because of permissions on the directory. We recommend that you use your favorite FTP client that supports SFTP or a Windows SFTP client such as WinSCP. For deployment of war files the easiest and recommended method is to use the Tomcat Manager http://example.com:8080/manager/html. More about Tomcat Manager.

Connect to your sever via SFTP as the root user. Navigate to;

/opt/tomcat/webapps/ROOT/

Now upload your .jsp and other files inside;

/opt/tomcat/webapps/ROOT/

Note: Make sure to remove the default index.jsp/index.html files and replace with your own.

Now set the User/Group on those files to tomcat nobody. You can do this from your SFTP client or from command line using,

chown -r tomcat.nobody *

If you only uploaded jsp, images and css files. Then you should be able to browse to the site you just uploaded by visiting http://example.com:8080

Note: If you upload a .war file using this example you will need to restart Tomcat for the war to be deployed;

service tomcat restart

Now that your site is visible. We normally would like to remove the requirement to use the port number in the URL for the site. For instance we would like to use http://example.com to access the site and not http://example.com:8080.

We can achieve this by using proxy_ajp. Download and edit or SSH directly the to server and edit;

/etc/httpd/conf.d/proxy_ajp.conf

At the bottom of the file add the line you see below;

ProxyPass / ajp://localhost:8009/

Now save the file and restart Apache to allow the changes to take effect;

service httpd restart

Congratulations! You should now have a fully configured Tomcat setup for this example.

Example two
Serving .jsp, .war from website Apache document root

The default Apache document structure for a Plesk domain is /var/www/vhosts/example.com/httpdocs

You can serve your files from the httpdocs directory or from a directory that you create inside just for that purpose. For this example we will be configuring the files to be served from this directory.

In this example you can upload your files using FTP or using an SFTP client. You will be uploading as the ftpuser you assigned to this domain during the domain setup process in Plesk.

Note: If this is the first time uploading to this new domain make sure to replace the default index.html with your own .html or .jsp. Once you have your files uploaded open the Tomcat server.xml and add the following host entry;

Trích dẫn:
<Host appBase="/var/www/vhosts/example.com/httpdocs/" name="example.com" unpackWARs="true" autoDeploy="true"> <Alias>example.com</Alias> <Context path="" docBase="webapps" debug="0" reloadable="true"/> <Logger className="org.apache.catalina.logger.FileLogger" prefix="example.com." suffix=".txt" timestamp="true"/> </Host>
This tells tomcat we want to serve the files from;

/var/www/vhosts/example.com/httpdocs/

Once you have completed adding this Context you will need to restart Tomcat for the changes to take effect.

service tomcat restart

As with Example one, at this point the site should be visable at http://example.com:8080.

Now that your site is visible. We normally would like to remove the requirement to use the port number in the URL for the site. For instance we would like to use http://example.com to access the site and not http://example.com:8080.

We can achieve this by using proxy_ajp. Download and edit or SSH directly the to server and edit;

/etc/httpd/conf.d/proxy_ajp.conf

At the bottom of the file add the line you see below;

ProxyPass / ajp://localhost:8009/

Now save the file and restart Apache to allow the changes to take effect;

service httpd restart

Congratulations! You should now have a fully configured Tomcat setup for this example.


2. How can I verify that Tomcat service works on my Plesk server.


Plesk uses regular Tomcat server that comes with your operation system. There are two ways to access JSP application on the Plesk server: through 9080 and 80 ports. If you access the application using 9080 port (like http://domain.tld:9080/WebAppName), you get response directly from the Tomcat server. If you open http://domain.tld/WebAppName/, then you access Apache Web server that forwards request to Tomcat on 9008 port by mod_jk accordingly to AJP13 connection configuration in the domain's httpd.include, for example:

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


Tomcat functioning itself can be checked using examples which are configured by default, open http://SERVER_IP:9080/examples/.
If you wish to verify Tomcat functioning on the domain, perform the following actions:

1. Create WAR archive from the examples application that are distributed with your Tomcat. To do it create ZIP archive of the directory with Tomcat example Applications.
For Tomcat4:
cd /var/tomcat4/webapps/examples
zip -r examples4.war ./


For Tomcat 5:
cd /var/lib/tomcat5/webapps/jsp-examples
zip -r examples5.war ./


2. Then upload this WAR through Plesk CP, restart Apache to force the web-applications to work immediately and check if it works.

If there are any problem with Tomcat, examine catalina.out for errors. It is usually locate in /var/log/tomcat5/catalina.out ( or /var/log/tomcat4/catalina.out for Tomcat 4 ).


3. [FIX] JSP scripts do not work after Plesk upgrade


Symptoms

JSP scripts do not work after Plesk upgrade:
Page not found error displayed instead of a correct page.

Cause

Most likely Java application was deployed on domain not through Plesk Control Panel, so MIME types were lost in website settings during Plesk upgrade.

Resolution

Corresponding MIME type should be configured in IIS manually. Go to IIS manager, Web Sites, domain.tld, Properties, HTTP header, MIME types, New

Extension: .jsp
MIME type: text/html


Chuc vui ve

Tong Hop


  Trả lời ngay kèm theo trích dẫn này
Gửi trả lời



Quyền Hạn Của Bạn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Hình Cảm xúc đang Mở
[IMG] đang Mở
Mã HTML đang Tắt




Bây giờ là 11:21 AM. Giờ GMT +7



Diễn đàn tin học QuantriNet
quantrinet.com | quantrimang.co.cc
Founded by Trương Văn Phương | Developed by QuantriNet's members.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.