<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.chepkov.com/w/index.php?action=history&amp;feed=atom&amp;title=Secure_Tomcat</id>
	<title>Secure Tomcat - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.chepkov.com/w/index.php?action=history&amp;feed=atom&amp;title=Secure_Tomcat"/>
	<link rel="alternate" type="text/html" href="https://www.chepkov.com/w/index.php?title=Secure_Tomcat&amp;action=history"/>
	<updated>2026-04-30T17:34:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://www.chepkov.com/w/index.php?title=Secure_Tomcat&amp;diff=271&amp;oldid=prev</id>
		<title>Vvc at 19:00, 21 July 2009</title>
		<link rel="alternate" type="text/html" href="https://www.chepkov.com/w/index.php?title=Secure_Tomcat&amp;diff=271&amp;oldid=prev"/>
		<updated>2009-07-21T19:00:24Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Securing Tomcat Installation ==&lt;br /&gt;
This article will help you to make your &amp;#039;&amp;#039;existing&amp;#039;&amp;#039; Tomcat installation more secure.&lt;br /&gt;
===Disable all unnecessary connectors===&lt;br /&gt;
By default tomcat listens on several ports and it is possible to connect to the tomcat instance from the network. We will limit connectivity only from loopback interface (localhost only) and only through AJP connector. This is bare minimum &amp;#039;&amp;#039;&amp;#039;server.xml&amp;#039;&amp;#039;&amp;#039; that will do the job done:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;Server&amp;gt;&lt;br /&gt;
 &amp;lt;GlobalNamingResources&amp;gt;&lt;br /&gt;
 &amp;lt;Resource name=&amp;quot;UserDatabase&amp;quot; auth=&amp;quot;Container&amp;quot; type=&amp;quot;org.apache.catalina.UserDatabase&amp;quot;&lt;br /&gt;
  description=&amp;quot;User database that can be updated and saved&amp;quot;&lt;br /&gt;
  factory=&amp;quot;org.apache.catalina.users.MemoryUserDatabaseFactory&amp;quot;&lt;br /&gt;
  pathname=&amp;quot;conf/tomcat-users.xml&amp;quot; /&amp;gt;&lt;br /&gt;
 &amp;lt;/GlobalNamingResources&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;Service name=&amp;quot;Catalina&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;Connector port=&amp;quot;8009&amp;quot; protocol=&amp;quot;AJP/1.3&amp;quot; address=&amp;quot;127.0.0.1&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;Engine name=&amp;quot;Catalina&amp;quot; defaultHost=&amp;quot;localhost&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;Realm className=&amp;quot;org.apache.catalina.realm.UserDatabaseRealm&amp;quot; resourceName=&amp;quot;UserDatabase&amp;quot; /&amp;gt;&lt;br /&gt;
   &amp;lt;Host name=&amp;quot;localhost&amp;quot; appBase=&amp;quot;webapps&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/Engine&amp;gt;&lt;br /&gt;
 &amp;lt;/Service&amp;gt;&lt;br /&gt;
&amp;lt;/Server&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now tomcat listens only on TCP port localhost:8009, can&amp;#039;t be more secure from network point of view. It&amp;#039;s also useless, since no one can connect to it from the outside. We need to provide a proxy agent who will listens on HTTP (TCP port 80) and HTTPS (TCP port 443) sockets, route requests to tomcat, get responses and send them back to the requester.  We will use [http://httpd.apache.org/ apache server] to accomplish the task.&lt;br /&gt;
&lt;br /&gt;
===Installing apache server===&lt;br /&gt;
We will use httpd version 2.2.11 (latest at this moment) since it has all required components (ssl, ajp) in the source tree.&lt;br /&gt;
* Download source code&lt;br /&gt;
* Extract it into current directory&lt;br /&gt;
 gunzip -c &amp;lt; httpd-2.2.11.tar.gz | tar xf -&lt;br /&gt;
* Sanitize the environment&lt;br /&gt;
 unset LD_LIBRARY_PATH&lt;br /&gt;
* Run configure script&lt;br /&gt;
*: We will install apache server into /usr/local/apache. Here we assume [http://www.openssl.org OpenSSL kit] is installed in /usr/local/ssl and [http://www.zlib.net ZLib library] is installed as a system library. If not, --with-z and --with-ssl options need to be adjusted accordingly&lt;br /&gt;
 cd httpd-2.2.11&lt;br /&gt;
 ./configure --prefix=/usr/local/apache --with-included-apr --enable-ssl --enable-mods-shared=all \&lt;br /&gt;
   --with-ssl=/usr/local/ssl --enable-proxy --enable-proxy-ajp&lt;br /&gt;
* Build and install apache&lt;br /&gt;
  make &amp;amp;&amp;amp; make install&lt;br /&gt;
&lt;br /&gt;
===Create SSL certificate for HTTPS connections===&lt;br /&gt;
* Generate SSL key &amp;#039;&amp;#039;&amp;#039;server.key&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
 cd /usr/local/apache/conf&lt;br /&gt;
 touch server.key&lt;br /&gt;
 chmod 600 server.key&lt;br /&gt;
 openssl genrsa -out server.key 2048 &lt;br /&gt;
* Create openssl config file &amp;#039;&amp;#039;&amp;#039;server-ssl.config&amp;#039;&amp;#039;&amp;#039;, here we assume server name is vvc.homeunix.net. Update all the fields appropriately&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[ req ]&lt;br /&gt;
default_bits = 2048&lt;br /&gt;
distinguished_name = req_dn&lt;br /&gt;
default_md = sha1&lt;br /&gt;
req_extensions = cert_type&lt;br /&gt;
prompt = no&lt;br /&gt;
[ req_dn ]&lt;br /&gt;
# country (2 letter code)&lt;br /&gt;
C=US&lt;br /&gt;
# State or Province Name (full name)&lt;br /&gt;
ST=Virginia&lt;br /&gt;
# Locality Name (eg. city)&lt;br /&gt;
L=Leesburg&lt;br /&gt;
# Organization (eg. company)&lt;br /&gt;
O=VVC&lt;br /&gt;
# Organizational Unit Name (eg. section)&lt;br /&gt;
OU=Apache server&lt;br /&gt;
# Common Name (*.example.com is also possible)&lt;br /&gt;
CN=vvc.homeunix.net&lt;br /&gt;
# E-mail contact&lt;br /&gt;
emailAddress=vvc@chepkov.com&lt;br /&gt;
[ cert_type ]&lt;br /&gt;
keyUsage=digitalSignature,keyEncipherment&lt;br /&gt;
extendedKeyUsage=serverAuth&lt;br /&gt;
subjectAltName=DNS:vvc.homeunix.net&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Generate certificate request &amp;#039;&amp;#039;&amp;#039;server.req&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
 openssl req -new -key server.key -out server.req -config server-ssl.config&lt;br /&gt;
* Obtain server certificate. Save it in server.crt&lt;br /&gt;
===Create apache configuration===&lt;br /&gt;
Here is the bare minimum &amp;#039;&amp;#039;&amp;#039;httpd.conf&amp;#039;&amp;#039;&amp;#039; that should provide you with all the functions outlined before&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerRoot &amp;quot;/usr/local/apache&amp;quot;&lt;br /&gt;
Listen 80&lt;br /&gt;
Listen 443&lt;br /&gt;
LoadModule authz_host_module modules/mod_authz_host.so&lt;br /&gt;
LoadModule setenvif_module modules/mod_setenvif.so&lt;br /&gt;
LoadModule proxy_module modules/mod_proxy.so&lt;br /&gt;
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so&lt;br /&gt;
LoadModule ssl_module modules/mod_ssl.so&lt;br /&gt;
LoadModule mime_module modules/mod_mime.so&lt;br /&gt;
LoadModule dir_module modules/mod_dir.so&lt;br /&gt;
LoadModule log_config_module modules/mod_log_config.so&lt;br /&gt;
User www&lt;br /&gt;
Group www&lt;br /&gt;
ServerAdmin vvc@chepkov.com&lt;br /&gt;
DocumentRoot &amp;quot;/usr/local/apache/htdocs&amp;quot;&lt;br /&gt;
&amp;lt;Directory /&amp;gt;&lt;br /&gt;
    Options FollowSymLinks&lt;br /&gt;
    AllowOverride None&lt;br /&gt;
    Order deny,allow&lt;br /&gt;
    Deny from all&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
LogLevel warn&lt;br /&gt;
LogFormat &amp;quot;%h %l %u %t \&amp;quot;%r\&amp;quot; %&amp;gt;s %b&amp;quot; common&lt;br /&gt;
CustomLog logs/access_log common&lt;br /&gt;
ErrorLog logs/error_log&lt;br /&gt;
DefaultType text/plain&lt;br /&gt;
TypesConfig conf/mime.types&lt;br /&gt;
# A client will get this message in case tomcat server is down&lt;br /&gt;
ErrorDocument 503 &amp;quot;The server is under maintenance&amp;quot;&lt;br /&gt;
SSLRandomSeed startup builtin&lt;br /&gt;
SSLRandomSeed connect builtin&lt;br /&gt;
ProxyPass / ajp://localhost:8009/&lt;br /&gt;
SSLPassPhraseDialog  builtin&lt;br /&gt;
SSLSessionCache &amp;quot;shmcb:logs/ssl_scache(512000)&amp;quot;&lt;br /&gt;
SSLSessionCacheTimeout  300&lt;br /&gt;
SSLMutex &amp;quot;file:logs/ssl_mutex&amp;quot;&lt;br /&gt;
&amp;lt;VirtualHost _default_:443&amp;gt;&lt;br /&gt;
SSLEngine on&lt;br /&gt;
SSLCipherSuite HIGH:!SSLv2:!ADH&lt;br /&gt;
SSLProtocol all -SSLv2&lt;br /&gt;
SSLCertificateFile conf/server.crt&lt;br /&gt;
SSLCertificateKeyFile conf/server.key&lt;br /&gt;
BrowserMatch &amp;quot;.*MSIE.*&amp;quot; nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Start apache server===&lt;br /&gt;
 /usr/local/apache/bin/apachectl start&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s all.&lt;/div&gt;</summary>
		<author><name>Vvc</name></author>
	</entry>
</feed>