You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Eric Berry <el...@gmail.com> on 2006/08/02 20:47:15 UTC

Virtual Hosting with Apache and mod_jk

Hi all,
   I'm still pretty new to this. I'm trying to set up a home server
for testing and learning purposes, and I'm having some troubles
setting up virtual hosts with Apache and mod_jk.

I have created a virtual host in my httpd.conf:
<VirtualHost *:80>
        DocumentRoot /opt/projects/www/com/townsfolkdesigns/web
        ServerName www.townsfolkdesigns.com
        /*.jsp ajp13
        /*.do ajp13
</VirtualHost>

and set up a host in server.xml:
<Host appBase="/opt/projects/www/com/townsfolkdesigns/web"
name="www.townsfolkdesigns.com">
   <Context docBase="/opt/projects/www/com/townsfolkdesigns/web" path="">
   </Context>
</Host>

This works great when I set up my hosts file to point
www.townsfolkdesigns.com to the correct IP of my server box.

However, if I try to access the server directly by IP, I get a 403
error. If I remove the virtual host, I can access the server directly
and get the default apache page. As I am still learning, I would like
to be able to get to the default apache page so I can read the
documentation as I fiddle around. So my first question is how do I set
it up so I can access my website via www.townsfolkdesigns.com, and
still get to the default apache page via direct IP?

My Second question is in regards to mod_rewrite, I want to be able to
use mod_rewrite to easily host a couple other domains on the same box.
Is there something like this for tomcat? I would like to be able to
declare one Host element (with a simple context element) in the
server.xml and have the requests directed to the correct paths. Is
this possible?

Thanks in advance for any help.
Eric

-- 
Learn from the past. Live in the present. Plan for the future.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT: Apache] Re: Virtual Hosting with Apache and mod_jk

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Eric,

> So all I need besides the
> workers.properties entries you mentioned previously, is to make sure
> that virtual hosts in httpd.conf have the JkMounts pointed to the
> worker I choose. That worker's port must coincide with a Connector
> configuration in the server.xml for an instance of tomcat.

Yup yup yup.

> Thank you again for all the help.

np

-chris



Re: [OT: Apache] Re: Virtual Hosting with Apache and mod_jk

Posted by Eric Berry <el...@gmail.com>.
Chris,
   Thank you so very much for all the help. So all I need besides the
workers.properties entries you mentioned previously, is to make sure
that virtual hosts in httpd.conf have the JkMounts pointed to the
worker I choose. That worker's port must coincide with a Connector
configuration in the server.xml for an instance of tomcat.

EX.
 [httpd.conf]
		<VirtualHost *:80>
			...
			ServerName www.aWebsite.com
			JkMount /*.jsp aWorker
			...
		</VirtualHost>
		<VirtualHost *:80>
			...
			ServerName www.bWebsite.com
			JkMount /*.jsp bWorker
			...
		</VirtualHost>


[aTomcatInstance:server.xml]
                <Connector port="8008"  enableLookups="false"
protocol="AJP/1.3" />

[bTomcatInstance:server.xml]
                <Connector port="8009"  enableLookups="false"
protocol="AJP/1.3" />

[workers.properties]
                workers.list=aWorker,bWorker
                aWorker.port=8008
                bWorker.port=8009

Thank you again for all the help.
Eric

-- 
Learn from the past. Live in the present. Plan for the future.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT: Apache] Re: Virtual Hosting with Apache and mod_jk

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Eric,

> However, I do not see anything regarding mod_jk in the txt. When
> setting up multiple instances, do I need to have mod_jk on different
> ports? Do I need to specify different Connector elements in the
> different server.xml files? Each one pointing to a different port?

You'll need more than one worker defined in workers.properties. Each
worker needs a separate target port, and each of your Tomcat instances
will need a different
ajp port to listen to.

I typically like an arrangement like this:

workers.properties:
workers.list=worker1, worker2, worker3, etc.
worker1.port=8185
worker2.port=8285
worker3.port-8385

(those are all 8x85 because it's nice to offer Apache access through
8x80, sometimes. it's just historical for me at this point)

httpd.conf:

Listen 8180
<VirtualHost *:8180>
    ...
    JkMount whatever worker1
    ...
</VirtualHost>

Listen 8280
<VirtualHost *:8280>
    ...
    JkMount whatever worker2
    ...
</VirtualHost>

etc.

You are free to provide everything using the same apache port (like 8888
or 8080 or 8180 or whatever). I typically offer everything through 8180
for my test apps, and regular old port 80 for production. If you want,
you can split everything up into separate apache ports (as shown above)
or merge them together into a single virtual host running on a single
port. Each app you map to Tomcat can live inside the same VirtualHost,
even if they are going to separate Tomcat instances.

Apache + mod_jk gives you a /ton/ of flexibility.

-chris


Re: [OT: Apache] Re: Virtual Hosting with Apache and mod_jk

Posted by Eric Berry <el...@gmail.com>.
Chris,
   I remembered seeing something about this when I downloaded tomcat,
and managed to find this in the RUNNING.txt.

==================================================
Advanced Configuration - Multiple Tomcat Instances
==================================================

In many circumstances, it is desirable to have a single copy of a Tomcat
binary distribution shared among multiple users on the same server.  To make
this possible, you can pass a "-Dcatalina.base=$CATALINA_BASE" argument when
executing the startup command (see (2)). In this
"-Dcatalina.base=$CATALINA_BASE" argument, replace $CATALINA_BASE with the
directory that contains the files for your 'personal' Tomcat instance.

When you use this "-Dcatalina.base=$CATALINA_BASE" argument, Tomcat will
calculate all relative references for files in the following directories based
on the value of $CATALINA_BASE instead of $CATALINA_HOME:

* conf - Server configuration files (including server.xml)

* logs - Log and output files

* shared - For classes and resources that must be shared across all web
           applications

* webapps - Automatically loaded web applications

* work - Temporary working directories for web applications

* temp - Directory used by the JVM for temporary files (java.io.tmpdir)

If you do not pass the "-Dcatalina.base=$CATALINA_BASE" argument to the
startup command, $CATALINA_BASE will default to the same value as
$CATALINA_HOME,
 which means that the same directory is used for all relative path resolutions.

The administration and manager web applications, which are defined in the
$CATALINA_BASE/conf/Catalina/localhost/admin.xml
and
$CATALINA_BASE/conf/Catalina/localhost/manager.xml files, will
not run in that configuration, unless either:
- The path specified in the docBase attribute of the Context element is made
  absolute, and replaced respectively by $CATALINA_HOME/server/webapps/admin
  and $CATALINA_HOME/server/webapps/manager
- Both web applications are copied or moved to $CATALINA_BASE,
  and the path specified in the docBase attribute of the Context
  element is modified appropriately.
- Both web applications are disabled by removing
  $CATALINA_BASE/conf/Catalina/localhost/admin.xml
  and
  $CATALINA_BASE/conf/Catalina/localhost/manager.xml.



However, I do not see anything regarding mod_jk in the txt. When
setting up multiple instances, do I need to have mod_jk on different
ports? Do I need to specify different Connector elements in the
different server.xml files? Each one pointing to a different port?

Thanks again for all the help,
Eric


-- 
Learn from the past. Live in the present. Plan for the future.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT: Apache] Re: Virtual Hosting with Apache and mod_jk

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Eric,

> Thank you for the advice regarding multiple instances of Tomcat, this
> is a great idea and I will read the documentation on it, but if there
> are any pointers anyone has they'd be greatly appreciated.

I don't know of any specific online documentation to point you to, but
you basically set CATALINA_HOME to a directory that contains a
"conf/web.xml", "conf/server.xml" and a "webapps" directory (usually
containing your webapp WAR files or just the whole, expanded webapp) and
run tomcat.sh (or tomcat.bat) from the real installation.

Tomcat uses the installation directory for all the normal stuff like
libraries and all that, and it uses the configuration in the directory
specified as CATALINA_HOME for everything else. So, you can have one
binary installation and several instances running off of it, all with
differing configurations.

I'm sure there /is/ documentation out there for this, I just don't
remember reading it ;)

> One last question, I recently tried to use Apache 2.2.3, and found
> that mod_jk wouldn't compile against it, has anyone had similar
> issues? I'm happy with Apache 2.0, but thought I'd ask.

I dunno. A buddy of mine uses 2.2.0 with no problem. Perhaps search the
list for recent similar problems, and start a new thread if you can't
find the solution?

-chris



Re: [OT: Apache] Re: Virtual Hosting with Apache and mod_jk

Posted by Eric Berry <el...@gmail.com>.
Hi Chris,
On 8/2/06, Christopher Schultz <ch...@christopherschultz.net> wrote:
> Eric,
>
> >        /*.jsp ajp13
> >        /*.do ajp13
>
> I assume these lines say "JkMount" before the paths...?

This is correct, sorry (bad rectangular copy).

> Are you using "name based virtual hosting" -- meaning that the hostname
> chooses the VirtualHost? Or, do you have multiple IP addresses pointing
> to the same server, and you are using IP address to choose the virtual host.
>
> If you are using "name based virtual hosting", then the ServerName head
> is /required/ to make it work: you cannot get it to work using just the
> IP address.

I'm using name based virtual hosting and found a solution to my first
problem by putting a VirtualHost in where the ServerName is the IP
address of the machine, and pointing the DocumentRoot to the manual
directory.
<VirtualHost *:80>
        DocumentRoot /opt/apps/apache2/manual
        ServerName 192.168.0.109
</VirtualHost>
(This works for me, since I'll only be accessing it through the local network)

> Generally, this is done with separate VirtualHost entries in httpd.conf,
> with a separate set of JkMount directives in each one: the configuration
> is handled entirely in Apache, so you don't have to do anything weird in
> your Tomcat configuration (as long as your <Engine>'s "defaultHost" is
> set to the same value as your simple <Host> entry).
>
> You do not need to use mod_rewrite to do this.
>
> If you are going to be running separate applications for each
> VirtualHost, I recommend running them in different instances of Tomcat.
> This will allow you to administer them separately. Also, if you have to
> take one of them offline (or one of them dies unexpectedly), the others
> are not interrupted.

I wanted to use mod_rewrite to avoid having to edit the httpd.conf and
server.xml files whenever I wanted to add another host, but since
there won't be more than 3 or 4, this will be fine. :)

Thank you for the advice regarding multiple instances of Tomcat, this
is a great idea and I will read the documentation on it, but if there
are any pointers anyone has they'd be greatly appreciated.

One last question, I recently tried to use Apache 2.2.3, and found
that mod_jk wouldn't compile against it, has anyone had similar
issues? I'm happy with Apache 2.0, but thought I'd ask.

Thanks again,
Eric


-- 
Learn from the past. Live in the present. Plan for the future.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


[OT: Apache] Re: Virtual Hosting with Apache and mod_jk

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Eric,

>        /*.jsp ajp13
>        /*.do ajp13

I assume these lines say "JkMount" before the paths...?

> This works great when I set up my hosts file to point
> www.townsfolkdesigns.com to the correct IP of my server box.
> 
> However, if I try to access the server directly by IP, I get a 403
> error.

Are you using "name based virtual hosting" -- meaning that the hostname
chooses the VirtualHost? Or, do you have multiple IP addresses pointing
to the same server, and you are using IP address to choose the virtual host.

If you are using "name based virtual hosting", then the ServerName head
is /required/ to make it work: you cannot get it to work using just the
IP address.

If you are /not/ using NameVirtualHost, then you should be able to get
your VirtualHost working by binding it to a specific IP address:

<VirtualHost 1.2.3.4:80>
       DocumentRoot /opt/projects/www/com/townsfolkdesigns/web
       ServerName www.townsfolkdesigns.com
       JkMount /*.jsp ajp13
       JkMount /*.do ajp13
</VirtualHost>

Someone should verify this; I'm not an Apache expert, but this seems
like the right solution.

> My Second question is in regards to mod_rewrite, I want to be able to
> use mod_rewrite to easily host a couple other domains on the same box.
> Is there something like this for tomcat? I would like to be able to
> declare one Host element (with a simple context element) in the
> server.xml and have the requests directed to the correct paths. Is
> this possible?

Generally, this is done with separate VirtualHost entries in httpd.conf,
with a separate set of JkMount directives in each one: the configuration
is handled entirely in Apache, so you don't have to do anything weird in
your Tomcat configuration (as long as your <Engine>'s "defaultHost" is
set to the same value as your simple <Host> entry).

You do not need to use mod_rewrite to do this.

If you are going to be running separate applications for each
VirtualHost, I recommend running them in different instances of Tomcat.
This will allow you to administer them separately. Also, if you have to
take one of them offline (or one of them dies unexpectedly), the others
are not interrupted.

-chris