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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Web Sites On Apache

Status
Not open for further replies.

Ladyhawk

Programmer
Jan 22, 2002
534
AU
Can anyone point me to some links or give me some information on how to host multiple web sites on Apache?

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
If you look at your httpd.conf file, you should see a directive called <VirtualHost>, below is the example from the typical conf file:

# Use name-based virtual hosting.
# Removed comment from next line
NameVirtualHost *

<VirtualHost *>
DocumentRoot &quot;/home/yourdirectory/public_html&quot;
ServerName yourdomain.com
ServerAlias yourdomain.com ServerAdmin webmaster@yourdomain.com
<Directory /home/yourdirectory/public_html>
Options Indexes IncludesNOEXEC
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/yourdirectory/srv-error_log
LogLevel notice
TransferLog /home/yourdirectory/srv-access_log
</VirtualHost>

More information can be found at
 
So I can set up virutal hosts for each web site. The web sites are only going to be intranet sites, does that matter? For testing, how can I cannect to one of the web sites on the server without putting the ip address in the host file?

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
I gave it a quick try and I could get two separate sites up locally by using the machine name for the first and the network ip for the second. My conf looked like this:

<VirtualHost *>
ServerName anyname
The rest of the directive
</VirtualHost>
<VirtualHost *>
ServerName machinename
The rest of the directive
</VirtualHost>

resolved to the 'anyname' or default vhost
resolved to the 'machinename' host.

I tried a subdomain of the machine name and was unsuccessful. The folder alias directives worked.
 
Only hitch I had was interaction between SSL and Virtual Host. Had to disable SSL to get it to work. Right now I have 8 sites served from a single IP, using virtual hosting. Works great.

Also, you can put in multiple Virtual Host entries pointing to the same website directory, so that XYZ.COM and XYZ.NET are physically the same pages on the server.

Howard
 
Me? It's internet, using dyndns.org DNS, Linksys NAT router with port 20 forwarded to linux RH8 box. Can also see it on the intranet, but only if entries are in HOSTS file on local machine.

HD
 
Where do I find the hosts file on the local machine?

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Scrap that last post... I found the hosts file.

As you can probably tell, I don't really know what I am doing with Apache. I have only ever set up IIS and now I have been thrown in the deep end. I need to set up three web sites on Apache and configure it so that the user just have to type in &quot;weba&quot; into their browser to get web site a. So all I need to do is map weba to the ip address of the web server and setup a virtualhost in Apache? One question with the DocumentRoot - in the examples it has / so is the under the Apache2 directory?

Sorry if I am asking some dum questions but I am trying to figure out as much as I can on my own and not bother you guys too much.

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
I think to set up more than two virtual hosts you may need to add a nic and use the ip address in the virtualhost directive to resolve it. If you figure out another way, post it, there are bound to be some others interested.

The document root can be anything you like as you can see in my first post. The default depends on the package you used to install apache, so if your site resolves to the default apache page you can look at you httpd.conf and determine its location. The directory / usually has the apache documentation and it is generally an alias. If you have not made any changes the entry below will show you the root. If you have a virtual host entry, then the first virtual host becomes the default server and root directory.

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory &quot;C:/phpdev/
 
This is what I have done so far. I have changed my hosts (on a client machine) file to reference the ip address of the server... such as

165.240.xxx.yyy ramsnew
165.240.xxx.yyy pmgnew

The two ip addresses are the same because it's the same server.

I have changed the httpd.conf file to include the following...

<VirtualHost *>
ServerName ramsnew
DocumentRoot ErrorLog logs/ramsnew-error_log
CustomLog logs/ramsnew-access_log common
</VirtualHost>

<VirtualHost *>
ServerName pmgnew
DocumentRoot ErrorLog logs/pmgnew-error_log
CustomLog logs/pmgnew-access_log common
</VirtualHost>

and I have created a under Apache2 and then a ramsnew directory and a pmgnew directory under the I have created a test.htm file in the ramsnew directory and one in the pmgnew directory so I know if it works or not.

I have restarted Apache.

When I enter I get the correct html page, but when I type in I get the same page. @#$%^

It shouldn't matter that both htm pages are called test.htm should it? What am I doing wrong?



Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Doh! Doh! Doh! Doh!

Is my face red?

I just saw that the &quot;NameVirtualHost *&quot; line was still commented out. Funny how it seems to work now.

Thanks for all of your help guys.



Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Glad you found your solution. You might also want to have a look at the FAQ's for this forum. [wink]
 
I did do a search before and it didn't seem to come up... sorry about that.

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
No problem, the Keyword Search function doesn't search the FAQ Area unless you select that option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top