Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache Virtual hosts

Status
Not open for further replies.

baden

Programmer
Feb 6, 2002
125
US
Let's say I have two companies that I am hosting for.

I want to set up Apache so that I can do somethin like this:

/company1/ and /company2/ reside within Tomcat to serve the servlets & jsp's, and I want the static html pages to be served by Apache. Can't get it working:

NameVirtualHost profitma-tuobr3

<VirtualHost profitma-tuobr3>
DocumentRoot &quot;C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/webapps/company1/&quot;
ServerName company1
#SSLEnable
ServerAdmin company1@profitma-tuobr3


JKMount /servlet/* ajp13
JkMount /*.jsp ajp13
JkMount /examples/* ajp13
JkMount /manager/* ajp13
JkMount /tomcat-docs/* ajp13
JkMount /webdav/* ajp13

ErrorLog logs/company1-error_log.log
CustomLog logs/company1-access_log.log common
</VirtualHost>

<VirtualHost profitma-tuobr3>
DocumentRoot &quot;C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/webapps/company2/&quot;
ServerName company2
#SSLEnable
ServerAdmin company2@profitma-tuobr3


JKMount /servlet/* ajp13
JkMount /*.jsp ajp13
JkMount /examples/* ajp13
JkMount /manager/* ajp13
JkMount /tomcat-docs/* ajp13
JkMount /webdav/* ajp13

ErrorLog logs/company2-error_log.log
CustomLog logs/company2-access_log.log common
</VirtualHost>
 
Hi,

Firstly, I'm not too sure on your use of 'profitma-tuobr3' in the NameVirtualHost directive and the Virtual Host containers. The parameter to both is an IP address or '*' meaning all IP addresses (all NICs) on the server. Maybe if that resolves to a valid IP address on the server its OK (haven't tried it though) but thats one thing I'd change.

The most obvious error is the ServerName directive. Under name based virtual hosts this should be set to the host part of the calling url. So if you want to access something with then you would have :

ServerName company1.servername.com

You can also use ServerAlias for alternative url matching - for example :

ServerAlias *.company1.servername.com

(would match etc)

Hope this helps
 
<VirtualHost 192.168.1.80>
DocumentRoot &quot;C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/webapps/ROOT/company1/&quot;
ServerName *.company1.profitma-tuobr3
# #SSLEnable
ServerAdmin company1@profitma-tuobr3
JKMount /servlet/* ajp13
JkMount /*.jsp ajp13

ErrorLog logs/company1-error_log.log
CustomLog logs/company1-access_log.log common
</VirtualHost

I am just testing this configuration out on my system (profitma-tuobr3) so...

Now when I go to it returns the index page located at $CATALINA_HOME/webapps/root. Also, I get an error &quot;Could not locate remote host&quot; when trying to do
In IIS you can setup virtual directories - how do you do this with Apache???
 
Ok, solution:


Alias /company1/ &quot;C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/webapps/ROOT/company1/&quot;

<Directory &quot;C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/webapps/ROOT/company1&quot;>
Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

Alias /company2/ &quot;C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/webapps/ROOT/company2/&quot;

<Directory &quot;C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/webapps/ROOT/company2&quot;>
Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>




I guess the same could be accomplished with:


JkMount /company1/* ajp13
JkMount /company2/* ajp13
 
Hi,

Maybe I wasn't too clear on the alias - you need the servername to be there all the time but you can also have a ServerAlias if you wish.

ServerName company1.servername.com
ServerAlias *.company1.servername.com

The simplest you can have for Name based virtual hosts is like this :

NameVirtualHost *

<VirtualHost *>
UseCanonicalName off
  DocumentRoot &quot;c:/whatever/server1&quot;
  ServerName company1.servername.com
</VirtualHost>

<VirtualHost *>
UseCanonicalName off
  DocumentRoot &quot;c:/whatever/server2&quot;
  ServerName company2.servername.com
</VirtualHost>

I'd suggest you get the basic containers working with a simple test html page in each DocumentRoot directory first before trying the servlet stuff.

The way name based hosts work is that (providing the browser is http/1.1 compliant and sends the info) the host field in the http request header is compared with the ServerName (and ServerAlias) values in each VirtualHost container in httpd.conf. If none match, then apache will default to selecting the one that appears first in httpd.conf. If the browser doesn't send the host: info then apache would also select the first virtual host container.

Obviously, if you have multiple adaptors and don't use '*' then it responds in this way only to requests received on the specified interface. So, if you set 'NameVirtualHost 192.168.1.80' then test via localhost then it would behave differently because you told Apache only to treat traffic on one interface as virtual host traffic.

Regards

 
I've done the following but still get the error that the server could not be located.

I got the going, I would really like to do
NameVirtualHost *

<VirtualHost *>
UseCanonicalName On
DocumentRoot &quot;C:\JAVADEV\Apache Group\Apache Tomcat 4.0.2\webapps\ROOT\company1&quot;
ServerName company1.profitma-tuobr3
</VirtualHost>

<VirtualHost *>
UseCanonicalName On
DocumentRoot &quot;C:\JAVADEV\Apache Group\Apache Tomcat 4.0.2\webapps\ROOT\company2&quot;
ServerName company2.profitma-tuobr3
</VirtualHost>
 
Sorry, I did use UseCanonicalName Off
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top