Sharing the Point

Office 365, SharePoint, Project Server – Support Blog

Posts Tagged ‘Tomcat’

How to Display Custom Error Page on Tomcat 6

Posted by Ashraf on December 3, 2010

If you are Unhappy with the default error pages that come with Tomcat then You can define your own custom error pages in your web.xml file after the following tag:

<welcome-file-list>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

In the example shown below, i define 2 html pages — web_server_error_500.html and file_not_found_404.html which will be displayed when the server encounters an error 500 or an error 404 respectively. Put your html files on tomcat6.0/webapps/Root folder.  And add this code on web.xml file.

<error-page>

<error-code>500</error-code>

<location>/web_server_error_500.html</location>

</error-page>

<error-page>

<error-code>404</error-code>

<location>/file_not_found_404.html</location>

</error-page>

Please be aware that the order of the tags for the web.xml file is very important. If the order in your web.xml file is incorrect, Tomcat will output errors on startup.

And for Internet Explorer users be sure you have enabled “Show custom error pages” from Internet Options>Advanced tab.

Posted in System Administration | Tagged: , , , | Comments Off on How to Display Custom Error Page on Tomcat 6

How to Configure Tomcat 6 – Custom Default Pages

Posted by Ashraf on December 1, 2010

Tomcat uses the same convention as the Apache Web Server in that index.html is

the default or home page of any directory. Sometimes you may want to change that

to homepage.html or maybe a JSP page, like home.jsp.

To do that, simply open the web.xml of your web application, and add the

following lines without commenting :

<welcome-file-list>

<welcome-file>home.jsp</welcome-file>

<welcome-file>homepage.html</welcome-file>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

To change it system-wide, edit the global web.xml in $CATALINA_HOME/conf, and

change the to point to the file of your choice.

Posted in System Administration, Windows Server | Tagged: , , , | Comments Off on How to Configure Tomcat 6 – Custom Default Pages

How to Redirect all http requests to https on Tomcat by default

Posted by Ashraf on November 23, 2010

***Considering that you already enable SSL with proper certificate.

To auto redirect all of your webserver requests from http to https just paste the following to your tomcat installation folder\conf\web.xml file and restart the service.

<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Context</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<!– auth-constraint goes here if you requre authentication –>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

Now browse http://localhost and it will automatically go to https://localhost , for example.

Posted in System Administration, Windows Server | Tagged: , , , , , | Comments Off on How to Redirect all http requests to https on Tomcat by default

Generate a Certificate Signing Request (CSR) for Tomcat with Keytool

Posted by Ashraf on October 24, 2010

To generate a Certificate Signing Request (CSR), perform the following steps:

Consider: Jdk1.6 and Windows Server with Tomcat 6.0

1. Create a certificate keystore and private key with the following command:

  1. i. C:\Program Files\Java\javaversionhere\bin>keytool -genkey -alias your_alaias_name -keyalg RSA -keystore your_keystore_filename
  2. ii. Specify the password – must be at least 6 characters long, and MUST be remembered.

2. You must input the following:
* What is your first and last name? *This is the Common Name Field – The Fully Qualified Domain Name MUST be entered here*
[Unknown]: http://www.yourdomain.com
* What is the name of your organizational unit?
[Global Sign]: IT
* What is the name of your organization?
[Global Sign]: MyOrganization
* What is the name of your City or Locality?
[London]:PARIS
* What is the name of your State or Province?
[London]: PARIS
* What is the two-letter country code for this unit?
[GB]: FR
* Is CN=www.yourdomain.com, OU=IT, O=MyOrganization, L=PARIS, ST=PARIS, C=FR correct?
[no]: yes
* Enter key password for
(RETURN if same as keystore password):

3. Create the Certificate Signing Request file with the following command:

  1. C:\Program Files\Java\javaversionhere\bin>keytool -certreq -keyalg RSA -alias your_alias_name -file certreq.csr -keystore your_keystore_filename
  2. Enter keystore password: your_password_here
  3. The certreq.txt file will now be generated – this file can be entered into the website. Insure to include:
    * —–BEGIN NEW CERTIFICATE REQUEST—–
    * —–END NEW CERTIFICATE REQUEST—–

Posted in System Administration, Windows Server | Tagged: , , , , | 3 Comments »

SSL Certificate Installation in Tomcat Web Server

Posted by Ashraf on October 24, 2010

NOTE: The certificate must be installed to the same keystore that was used to generate your CSR. If you try to install it to a different keystore it will not work.

Installing The Certificates to the Keystore

1. Download your SSL Certificate file (example: mycertificate.p7b) from your certificate authority Account to the directory where your keystore was saved during the CSR creation process.

2.Type the following command to install the certificate file to your keystore:

keytool -import -trustcacerts -alias tomcat -file mycertificate.p7b -keystore .keystore

You should get a confirmation stating that the “Certificate reply was installed in keystore”

If it asks if you want to trust the certificate. Choose y or yes.

Your keystore file (.keystore) is now ready to use on your Tomcat Server and you just need to configure your server to use it.

Configuring your SSL Connector

Tomcat will first need an SSL Connector configured before it can accept secure connections.

1. Open the Tomcat server.xml file in a text editor (this is usually located in the conf folder of your Tomcat’s home directory).
2. Find the connector that will be secured with the new keystore and uncomment it if necessary (it is usually a connector with port 443 or 8443 like the example below).
3.Specify the correct keystore filename and password in your connector configuration. When you are done your connector should look something like this:

<Connector port="443" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true" SSLEnabled="true" clientAuth="false" sslProtocol="TLS" keyAlias="tomcat" keystoreFile="c:\tomcat6.0\conf\.keystore keypass="your_keystore_password" />

4. Save your changes to the server.xml file.
5. Restart Tomcat.

Posted in System Administration, Windows Server | Tagged: , , , | Comments Off on SSL Certificate Installation in Tomcat Web Server

 
%d bloggers like this: