Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 908
  • Last Modified:

how to do virtual hosting with tomcat and apache

Does anyone know how to do virtual hosting with linux/tomcat/apache? I've had several questions posted for several days with no response. I'll try again on EE.

I have tomcat running fine. I've configured virtual hosting for apache before.  That's my starting point. Can't figure out how to specify correct paths, contexts, etc. ... please help.
0
jmarkfoley
Asked:
jmarkfoley
  • 6
  • 5
1 Solution
 
mrcoffee365Commented:
Why don't you post some information about your configuration and we'll help you through the problems?

For future reference, posting on a Saturday is less likely to get immediate help, especially for more business level issues like apache and tomcat.  So you might wait until Monday before giving up on questions like your previous ones which are now deleted.
0
 
jmarkfoleyAuthor Commented:
Sorry for the impatience. I did post some of those during the work-week. In fact, I've found that posting a lot of info tends to limit responses, but posting a short question does get response, even if I have to post more detail later. So, here is the detail, and I promise to be more patient.

I've included the relevant sections of my httpd.conf, workers.properties and server.xml. Apache is installed at /usr/local/apache. CATALINA_HOME is /www/tomcat. Currently all contexts are under $CATALINA_HOME/webapps. I am not using WAR files but rather they are unpacked. The only context I have configured at the moment is $CATALINA_HOME/webapps/courtscan.

I have (or would like to have) three virtual hosts: www.fluxrunner.com (the default host), www.courtscan.com and www.buffalotouch.com. Currently, only courtscan is JSP. The others are regular ole static html and I would like the DOCUMENT_ROOT to be under /www/fluxrunner and /www/buffalotouch, respectively. My problem is that, given my current setup, everything is being routed to tomcat and wants to find things for fluxrunner and buffalotouch under CATALINA_HOME.

thank you, this is driving me nutz!!

httpd.conf - tomcat setup
-------------------------
LoadModule    jk_module  lib/mod_jk.so
workers.properties ne$
JkWorkersFile conf/workers.properties
JkShmFile     /var/log/httpd/mod_jk.shm
JkLogFile     logs/mod_jk.log
JkLogLevel    info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
#JkMount  /courtscan courtscan
#JkMount  /courtscan/* courtscan
 
httpd.conf - virtual host section
----------------------------------
NameVirtualHost *
 
<VirtualHost *>
 ServerName www.fluxrunner.com
 DocumentRoot /usr/local/apache/htdocs
</VirtualHost>
 
<VirtualHost *>
 ServerName www.courtscan.com
 DocumentRoot /www/courtscan
 
<directory /www/courtscan>
allow from all
</directory>
 
 CustomLog /www/courtscan/logs/access_log combined
 ErrorLog /www/courtscan/logs/error_log
</VirtualHost>
 
<VirtualHost *>
 ServerName www.buffalotouch.com
 DocumentRoot /www/buffaloTouch
 
<directory /www/buffaloTouch>
allow from all
</directory>
 
 CustomLog /www/buffaloTouch/logs/access_log combined
 ErrorLog /www/buffaloTouch/logs/error_log
</VirtualHost>
 
server.xml - <Host> section
---------------------------
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
      </Host>
 
      <Host name="www.courtscan.com" appBase="webapps"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
        <Alias>courtscan.com</Alias>
        <Logger className="org.apache.catalina.logger.FileLogger" directory="logs/" prefix="courtscan_access_log" suffix=".log" timestamp="true"/>
 
        <Context path="" docBase="courtscan" reloadable="false">
          <WatchedResource>/WEB-INF/web.xml</WatchedResource>
        </Context>
      </Host>

Open in new window

0
 
jmarkfoleyAuthor Commented:
Oops! forgot to post workers.properties:

worker.list=courtscan
worker.courtscan.type=ajp13
worker.courtscan.port=8009
worker.courtscan.mount=/ /*

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
mrcoffee365Commented:
So this isn't a Tomcat question, but an Apache question.  You only want courtscan.com to go to Tomcat.  

The Apache configuration looks okay, but it would be good to add the Directory tag to all of the virtual hosts (you don't have it for fluxrunner).

Do you have a Location tag set in your httpd.conf?  

What version of Apache are you running?
0
 
jmarkfoleyAuthor Commented:
hmmm, for some reason I didn't get an email notice about you comment.
Apache/2.2.11, tomcat: 6.0.18.

I'm not sure it is an Apache-only question. In the absence of tomcat things get routed properly to the specified DOCUMENT_ROOT. I have a feeling that it is the workers.properties:worker..mount path=/ /* that is causing everything to be sent to tomcat ... but I'm not sure.

I do not have a Location tag in httpd.conf, but I have looked at the docs on it. What are you suggesting here? SetHander to tomcat? AllowFrom?
0
 
mrcoffee365Commented:
From my perspective, the workers.properties files and the uriworkermap.properties files are related to Apache, since they only concern the connecter between Apache and Tomcat.

I think your workers.properties file is fine.  What does your uriworkermap.properties file look like?

If you aren't using one, then you have to do the JkMount directives in the Apache httpd.conf file.  The ones in your post are commented out -- do you have them somewhere else in the file?  See the section in this page on assigning URLs to Tomcat:
http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html

See here for documentation of the Location directive:
http://httpd.apache.org/docs/1.3/mod/core.html#location
However, I think that it's more for access control, and will not help your immediate problem.
0
 
jmarkfoleyAuthor Commented:
Thanks for the feedback. Lots more questions. I am familiar with the tomcat link you provided and it was what I used to do my initial setup. On that page, in the 'ajp13 Worker properties' section, it states, "mount can be used as an alternative to the JkMount directive." That is why my JkMount is commented out in the httpd.conf file: I was using the "alternative" (or so I thought).

So, I removed the mount directive from the workers.properties file and put the following back in httpd.conf:

JkMount / courtscan
JkMount /* courtscan

This essentially worked the same as before, all request routed to tomcat. Then I tried:

JkMount  /courtscan courtscan
JkMount  /courtscan/* courtscan

This permitted other virtual hosts to then get to their respective DOCUMENT_ROOTs, but now the courtscan context didn't work. Makes sense. the URL is http://www.courtscan.com, not http://www.courtscan.com/courtscan. So, using or not using JkMount doesn't help, at least with what I tried.

How does uriworkermap work? I've tried to find documentation on uriworkermap.properties. The link you gave, under the uriworkermap link, simply says, "Please consult the web server specific documentation pages on how to enable the uriworkermap file." Big help. I found nothing looking in apache.org directives. Other web searches indicate I need a JkMountFile directive in my httpd.conf, e.g.:
JkMountFile  /path/to/httpd/conf/uriworkermap.properties
Some examples show this as being placed in my <Virtual Host> section, e.g.:

<VirtualHost *>
 ServerName www.courtscan.com
 DocumentRoot /www/courtscan

JkMountFile  /path/to/httpd/conf/uriworkermap.properties

<directory /www/courtscan>
allow from all
</directory>

 CustomLog /www/courtscan/logs/access_log combined
 ErrorLog /www/courtscan/logs/error_log
</VirtualHost>

Does this seem right to you?

What should my uriworkermap.properties look like? Examples:
/courtscan|/*=courtscan
/www.courtscan.com|/*=courtscan

neither of the above work.
0
 
mrcoffee365Commented:
It would work best to put your JkMount directives in your Virtual Host sections.  

I don't think you should use both uriworkermap.properties and JkMount in your httpd.conf file -- remove the uriworkermap.properties and try making JkMount work for you.

0
 
jmarkfoleyAuthor Commented:
YEAH!!!! That did it! All this trauma and all I had to do was move the JkMount into the virtual host section! Sheesh!
0
 
jmarkfoleyAuthor Commented:
Thanks a lot!!!!!!!!!
0
 
mrcoffee365Commented:
Congrats!  It's like that for so many things, especially configuration.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now