title: Tomcat: Restrict access to localhost for /just one/ webapp
body: <p>I'm running Tomcat 6 to serve several web apps, most of which are public-facing.  But I'd like to restrict access to <em>just one</em> webapp, allowing connections only from localhost.</p>
  
  <p>I can restrict access for <em>all</em> webapps using a valve in context.xml, as described in:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/3381531/tomcat-restrict-access-by-ip-address">Tomcat Restrict access by IP address</a></li>
  </ul>
  
  <p>But I can't figure out how to restrict access on a per-app basis.  Is there a way to do this with my app's web.xml?  Or by adding additional rules to context.xml?</p>
  
  <p>Thanks,</p>
  
  <p>-B</p>
  
  <hr>
  
  <h1>Recapping Solution:</h1>
  
  <pre><code>$ cp /var/lib/tomcat6/conf/context.xml \ 
     /var/lib/tomcat6/conf/Catalina/localhost/my-app-name.xml
  
  $ cat /var/lib/tomcat6/conf/Catalina/localhost/my-app-name.xml
  
  &lt;Context&gt;
      &lt;Valve className="org.apache.catalina.valves.RemoteHostValve" allow="localhost"/&gt;
  ... {as previously} ...
  &lt;/Context&gt;
  </code></pre>