• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

virtual hosts

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm trying set up two virtual hosts (two seperate websites) on apache. My understanding is that all I need to edit is the httpd.conf file. So I have. I have tried:

<VirtualHost *>
ServerName www.tjtflooring.ca
DocumentRoot /var/www/html
DirectoryIndex index.html index.htm index.shtml
ErrorLog /etc/httpd/logs/error_log
TransferLog /etc/httpd/logs/access_log
</VirtualHost>

<VirtualHost *>
ServerName scholastictrackssandbox.ca
DocumentRoot /var/www/sandbox
DirectoryIndex index.html index.htm index.shtml
ErrorLog /etc/httpd/logs/error_log
TransferLog /etc/httpd/logs/access_log
</VirtualHost>

as well as a number of other combinations such as:

<VirtualHost www.tjtflooring.ca>
ServerName www.tjtflooring.ca
DocumentRoot /var/www/html
DirectoryIndex index.html index.htm index.shtml
ErrorLog /etc/httpd/logs/error_log
TransferLog /etc/httpd/logs/access_log
</VirtualHost>

<VirtualHost scholastictrackssandbox.ca>
ServerName scholastictrackssandbox.ca
DocumentRoot /var/www/sandbox
DirectoryIndex index.html index.htm index.shtml
ErrorLog /etc/httpd/logs/error_log
TransferLog /etc/httpd/logs/access_log
</VirtualHost>

and

<VirtualHost 192.168.2.83>
ServerName www.tjtflooring.ca
DocumentRoot /var/www/html
DirectoryIndex index.html index.htm index.shtml
ErrorLog /etc/httpd/logs/error_log
TransferLog /etc/httpd/logs/access_log
</VirtualHost>

<VirtualHost 192.168.2.83>
ServerName scholastictrackssandbox.ca
DocumentRoot /var/www/sandbox
DirectoryIndex index.html index.htm index.shtml
ErrorLog /etc/httpd/logs/error_log
TransferLog /etc/httpd/logs/access_log
</VirtualHost>

As you can see they are sharing the same IP address. There is only one NIC card in the server. Yet I'm told it is supposed to be possible to set up multiple websites on a single server.

The last two keep giving me error messages. The only one that doesn't is the first one with the * wildcard. But none of them really work the way I want! With all of them, the second VirtualHost is totally ignored. When I open my browser and type in www.scholastictrackssandbox.ca I'm taken to the DocumentRoot of www.tjtflooring.ca which is /var/www/html. However, I explicity set the DocumentRoot for sholastictrackssandbox.ca to /var/www/sandbox.

I'm really frustrated. Please someone explain to me what I need to do set this up properly.

Regards,

Alan
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Alan Shiers:

<VirtualHost *>
ServerName www.tjtflooring.ca
DocumentRoot /var/www/html
DirectoryIndex index.html index.htm index.shtml
ErrorLog /etc/httpd/logs/error_log
TransferLog /etc/httpd/logs/access_log
</VirtualHost>

<VirtualHost *>
ServerName scholastictrackssandbox.ca
DocumentRoot /var/www/sandbox
DirectoryIndex index.html index.htm index.shtml
ErrorLog /etc/httpd/logs/error_log
TransferLog /etc/httpd/logs/access_log
</VirtualHost>



I notice that you have left off the 'www' part of scholastictrackssandbox.ca, perhaps that is the reason? Since the 'www' version is not specified it will default to some other document root (perhaps this is /var/www/html defined earlier in your httpd.conf?)

Cheers, Jared.
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you include the line



in your httpd.conf? After that you can use the



form of virtual hosts. Remember that you may want a "default" virtual host - the first one listed. This might be the IP address of your machine so that if someone goes directly to the IP it will use that one.
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You were right. It was the fact that I left off the triple www on the URL for scholastictrackssandbox.ca. It's working now. Thanks. Sometimes I just can't see the forest for the trees!

Alan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!