Category Archives: Tomcat

How to automatically restart tomcat after system reboot – Ubuntu Linux

First create a file in /etc/init.d/tomcat

sudo nano  /etc/init.d/tomcat

Then add the contents below



start() {
 sh /home/server/tomcat/bin/ # Change this location to your tomcat directory

stop() {
 sh /home/server/tomcat/bin/ # Change this location to your tomcat directory

case $1 in
  start|stop) $1;;
  restart) stop; start;;
  *) echo "Run as $0 <start|stop|restart>"; exit 1;;

Change permissions

chmod 755 /etc/init.d/tomcat

Update symlinks

update-rc.d tomcat defaults

Test, if you did everything correctly by

sudo service tomcat <stop|start|restart>

Http to Https redirect on Tomcat

This post assumes that:

  • You have bought the SSL
  • Have successfully installed it on Tomcat with Keytool

Now you are trying to figure out how to automatically redirect http to https.

You will need to edit two files under Tomcat configuration: server.xml and web.xml. Then restart tomcat to reflect the changes.

Step 1:

Open server.xml and find

<Connector port="80" protocol="HTTP/1.1"
 redirectPort="8443" />

Change to

<Connector port="80" protocol="HTTP/1.1"
 redirectPort="443" />

And make sure you have these lines as well. Change KeystoreFile and KeystorePass according to your details

<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
 maxThreads="150" scheme="https" secure="true"
 keystorePass="certificatename" clientAuth="false" sslProtocol="TLS">

Step 2:

Open web.xml ( not the one under tomcat/conf/web.xml but where your site folder is something like /site-folder/WEB-INF/conf/web.xml) and add these lines before the ending </web-apps> tag.

 <web-resource-name>Protected Context</web-resource-name>
 <!-- auth-constraint goes here if you require authentication -->

Now restart the tomcat and all pages should redirect to https