vicker313 tech blog

February 14, 2010

Redirect from HTTP to HTTPS in Tomcat

Filed under: Tomcat — Tags: , , , — vicker313 @ 9:09 am

Simple method to configure Tomcat (the version I try is Tomcat 6) so that all HTTP access will redirect to HTTPS.

Edit [TOMCAT_HOME]\webapps\ROOT\WEB-INF\web.xml, add the following codes inside the web-app tag (or just the above of </web-app>).
<security-constraint>
<web-resource-collection>
<web-resource-name>Automatic SSL Forwarding</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

Advertisements

January 21, 2010

Install Tomcat Startup Script in Linux

Filed under: Tomcat — Tags: , — vicker313 @ 8:00 am

Make Tomcat auto startup in Windows is easy, either install it as service or just put the startup batch into Windows startup list. But not for Linux. After you install (or unzip) Tomcat into your Linux machine, and everything tested OK, you can use steps below to make Tomcat startup as service in Linux (referring to Startup script for Tomcat on Centos | Redhat | Fedora):

  1. Download the startup script from here. There are 2 files inside the zip file: tomcatd and tomcatRunner.
  2. Extract them to /etc/init.d. Make sure they are runnable.
  3. Edit parameters below inside tomcatd file:
    1. JAVA: location of your java utility, for example /usr/java/jdk1.6.0_17/bin/java.
    2. tomcatuser: user that will run the service, usually I just change it to root. (default is tomcat)
    3. CATALINA_HOME: location of your Tomcat, example /usr/tomcat.
  4. Make a tomcat directory in /var/run:
    mkdir /var/run/tomcat
  5. Add the tomcat service:
    chkconfig ––add tomcatd
  6. Now you should able to test out the service:
    service tomcatd restart

Here is another post to auto start Tomcat.

August 8, 2009

Add Tomcat Virtual Directory

Filed under: Tomcat — Tags: , — vicker313 @ 8:00 am

In Apache Tomcat, if we want to add a sub directory into an url, such as vicker313.wordpress.com/subdir, we will normally create a new directory at the [tomcat]\webapp directory, and put in the necessary web pages.

However if we need to put the web pages outside webapp, then we need to create a virtual directory in Tomcat:

  1. Go to [tomcat]\conf\Catalina\localhost (version that I used is 5.5).
  2. Create a xml file, named it as the name of the directory that store your web pages, for example subdir.xml.
  3. Put in the following code (assume your directory is c:\subdir):
    <?xml version="1.0" encoding="UTF-8"?>
    <Context path="/subdir" docBase="c:/subdir" debug="0" privileged="true"></Context>
  4. Now you can access the site http://www.yoururl.com/subdir

It is also possible to point the virtual directory to a shared folder of another machine:

<Context path="/subdir" docBase="//192.168.1.2/subdir" debug="0" privileged="true"></Context>

Beware that the directory that you point must have the web pages, as lease an index.html. Or else it will just show out no resource error message (will not list out the content of the directory).

« Newer Posts

Create a free website or blog at WordPress.com.