Reputation: 49
I have a VirtualBox Ubuntu Server with Java 8 and Tomcat 8. I want to use Tomcat to serve all web content using it's webapps directory for all my Java apps and create a webdocs directory at the same level and permissions for all my static html websites.
I also have security that checks each URL serving a login if necessary so serving my static html can't be based on the URL path. I want to replicate Apache2's ability to match a domain name and serve the associated docBase. The following is my server.xml attempting to add a Context Path for my static html within the Engine tag:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="mywebsite.com" appBase="webdocs">
<Alias>www.mywebsite.com</Alias>
<Context path="" docBase="/mywebsite/" />
</Host>
I've tried variations of the above, but get 404 codes or access denied. I'm sure there is conflict with my web.xml where security is designed to intercept each URL. As I said, I need to keep security doing the same, but want domain names to resolve to the docBase similar to what Apache2 does.
Lastly, how can I use domain names instead of 192.168.x.x:8080/ to mimic my production server? Is there a way to do that on my laptop running VirtualBox?
Any help would be greatly appreciated.
Thanks,
Brandon
P.S. I know I have to setup my IPTable Rules to reroute 8080 to 80 and 8443 to 443 and next get multiple SSL certificates configured in Tomcat. I'm taking each of these configurations in steps.
UPDATE: I was able to get Tomcat to host my static html OUTSIDE of webapps using a new Host and Context element in my sever.xml:
<Host name="mywebsite.com"
appBase="/home/webdocs"
unpackWARs="true"
autoDeploy="true">
<Alias>www.testmywebsite.com</Alias>
<Context path=""
docBase="mywebsite"
reloadable="false" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs"
prefix="testmywebsite_access_log"
suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
The appBase defines the location of my static html and docBase defines the folder containing the website's specific html relative to appBase. The name and alias attributes define the domain name requests Tomcat will match and serve NOT DEPENDENT on the path of the URL.
Upvotes: 0
Views: 386
Reputation: 4067
Apache2's ability to match a domain name and serve the associated docBase
This is called "virtual host".
I suppose the most reliable solution would be to use Tucky URL rewriter filter to detect the host and direct requests to particular handler, or specific path for static content (say from /* to /webdocs/*).
how can I use domain names instead of 192.168.x.x:8080/ to mimic my production server
Use the hosts file (/etc/hosts in UNIX, %WINDIR%\system32\drivers\etc\hosts in Windows)
Upvotes: 0
Reputation: 311018
The easy way would be to define webdocs
as a webapp, with its own web.xml and Context.xml. It doesn't need to contain any code.
Upvotes: 0