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

how do they do virtual hosting like that?

Status
Not open for further replies.

JCrou82

Programmer
Joined
Aug 23, 2002
Messages
265
Location
US
Hello, I am slightly familiar with setting up apache and modifying the config file. This is my scenario. We have three or more domain names hosted on this machine. They are all hitting the correct directories where the web files are located.

heres what happens. If i type in or xx.xxx.xxx.xx (ip address) it goes to the main directory. but when i type in a different address which we host, it goes to that particular subdirectory, but on the address bar, it goes to where domainname is the name of the subdirectory. Now I know that you can do virtual hosts, but when I read the httpd.conf file, i saw nothing about virtual hosts nor anything mentioning this particular subdirectory. In other words, it seems as if it magically knows where to look for that domain.
My question is how is it set up, and wether it's an ISP set up or if apache has been configured to do that. What I would like to do, is eliminate and have the root folder for that domain name point to the particular subdirectory.

Thanks in advance if anyone can help me figure this out.
 
it's already pointing to the htdocs directory. That works fine. The issue though is how did they point to go to which is found in .../htdocs/site2directory/.

In other words, I don't want to tell the visitor what the name of the root directory is for the site2.com. I'm not sure if i'm explaining this correctly. I don't see any virtual hosts set up in the apache config files, yet we are using virtual hosts. I wasn't the person who set it up, and though it works fine, I would like to know how to improve it a bit.


Thanks in advance
 
Hi mate,

As I said before, just set the DocRoot of the virtualhost to be /htdocs/site2directory

Hope this helps Wullie

sales@freshlookdesign.co.uk

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
I'm sorry wullie, I don't mean to sound like I wasn't listening. I found the answer. What I was attempting to say was that it seemed as if the server was configured one way, but the configuration file was telling it to be configured another way. The answer is that I was looking at the wrong config file and whoever set this up prior to me is telling Apache to look for a different variation of the config file called httpd.conf.new as opposed ot httpd.conf, which is where I was looking.

Thanks any ways
 
Actually, I am puzzled again. I am looking at the httpd.conf file and I see nothing there regarding virtual hosts. However, there is a file named httpd.conf.new that has the virtual hosts but the DocumentRoot values is pointing to a subdirectory that has no files in them. I wanna know how is the webserver functioning correctly when the config files are incorrect? Also want to know what is the name of the files that tells Apache how to run (such as httpd.config) and where could I possibly find them? In other words, is there a file that says, "look for these files with these names and run according to the specifications laid out in those particular files"? or somewhere that I can get that kind of info?
 
Hi mate,

The main Apache document root is useless after you add a virtualhost. The virtualhost takes over in this case.

Hope this helps Wullie

sales@freshlookdesign.co.uk

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
Each virtual host has its own document root specified in each vhost container within httpd.conf:

<VirtualHost *>
DocumentRoot /var/ ServerName ........yada yada yada .........
</VirtualHost>

<VirtualHost *>
DocumentRoot /var/ ServerName ........yada yada yada .........
</VirtualHost>

This is what tells apache where to find the document root, aliased cgi-bin, directory specs, etc.

Can you post the vhost and other pertinent sections of your http.conf file (names changes to protect the innocent, of course!)? It would make it easier to see the root cause of the problem.
 
when i get in the office I will send it to you wlwoman. The truth of the matter is that there is no problem with the webserver it's just odd the way it functions.

For instance by memory I remember the file named httpd.conf.new containing something like this:

<VirtualHost>
DocumentRoot /server/site1.com
ServerName ........yada yada yada .........
</VirtualHost>

but when i go to the server directory and look in the site1.com directory, there are NO files in there.
Yet when you go to on the browser, it &quot;redirects&quot; (might be the word) to The files for this site ARE found in .../htdocs/site1, but I see NO files pointing or even telling the server to look for the site in this directory. All I see is what I typed in above and there are no files in there. That is where my confusion lies. How is Apache running correctly when the config file is not set up correctly.
 
httpd.conf.new isn't the file you want to look in. It's just the new httpd.conf that was installed with a RPM or the like. //Daniel
 
Yes, danielhozac, I figured that this wasn't the file, but the only file I found with the name httpd.conf didn't have any virtual hosts. The only file I had found with virtual host set up was that httpd.conf.new file. This is where my problem lies. The correctly named file does not have the correct info. So as of right now I am VERY confused. When I get in to the office in a few hours, I will research other possibilites and send in what my httpd.conf file looks like.

If any one has any issues like this, I would greatly appreciate your suggestions.
 
I went to look at settings from our ISP since they are the ones who we point to for our DNS settings, I didn't find anything there. So as promised here are the settings found in my httpd.conf file, verbatim:

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot &quot;/usr/local/apache/htdocs&quot;
.
.
.
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory &quot;/usr/local/apache/htdocs&quot;>
.
.
.
NameVirtualHost xx.xxx.xxx.xx:80
.
.
.
##All VirtualHost Info is commented out and not even pointing to the right directiories anyway.

I still don't know how Apache is point the domain name..( to look for the web files in the site1dir directory. What I get in the browser's address bar when I type in is
Still haven't figured out how this happens.

Any help is greatly appreciated.
 
take a close look at your httpd.conf Is there a statement to INCLUDE vhosts.conf? If so, maybe that's where your answer lies.
 
thanx smah, that's what I was thinking but couldn't remember. Unfortunately I found nothing in the httpd.conf file nor any file within the machine with the name vhosts.conf. I was hoping that to be the answer, but unfortunately it wasn't. Still don't know what else it could be. Could there be settings in Linux that tell Apache where to go if visitors typed in on url instead of another, or is the only way of doing that in the httpd.conf file? I will continue searching in hopes to find SOME possible answer.

If any one has any possible scenarios that could be happening, please let me know.

Thak you
 
Here is the scenario. When it was set up, they might have attempted to get VirtualHosts in the httpd.conf file to work and for some reason didn't continue with it. So instead what was done was an &quot;index.html&quot; file was created that had coded a javascript function in the <head> section of the index.html file to go to an &quot;index.php&quot; file:

<SCRIPT LANGUAGE=JavaScript>
<!--
function go_now()
{
window.location.href=&quot;index.php&quot;;
}
//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR='#FFFFFF' onLoad=&quot;go_now()&quot;>
<!--the rest of the html code omitted for brevity issues-->
***********************

Then in the &quot;index.php&quot; file there is a require statement to require an include file named &quot;siteData.inc&quot;:

<?
require(&quot;slugs/siteData.inc&quot;); //get template particulars
//.....other php code
?>
<!--<html> etc.....--->
*************************

And in the siteData.inc file we have this:
<?
$headers = getallheaders();
/*
while ( list($k,$v) = each($headers) )
{
print(&quot;\$headers[$k]=$v<BR>&quot;);
}
*/
if ( ereg('site1.com',$headers['Host']) )
$dir = 'site1.com';
else if ( ereg('site2.com',$headers['Host']) )
$dir = 'site2.com';
else if ( ereg('site3',$headers['Host']) )
header(&quot;Location: else if ( ereg('site4',$headers['Host']) )
header(&quot;Location: else if ( ereg('site5.com',$headers['Host']) )
header(&quot;Location: else
$dir = 'site2.com';

include(&quot;$dir/siteData.inc&quot;);
?>

This has got to be the way it was set up. A few questions.
1. Is this a preferred way, I mean it's working fine now, but should I go edit the httpd.conf file to do virtualhost. I am pretty sure that the reason it wasn't done this way was because they had SSL installed on here as well and virtualHosting does not allow for name based only for ip based (from httpd.apache.org/docs/vhosts/name-based.html). But now we no longer need the SSL thought we might revert back to it.

2. I know what the last peace of code actually does, but I don't know how it actually works. I attempted to change this code to make let's say site3 (a live site) actually go to but it didn't work. So I am a little confused as to what's happening there.

Thank You all for your help so far and for any future help.
 
to answer wullie, there are no .htaccess files any where
 
This really isn't a preferred way of doing it. Using VirtualHosts would increase performance tremendously. //Daniel
 
I agree with Daniel. That script should be thrown out the window. That is why you get the path when accessing the different domains. You want to use vhosts with a container that has at least a DocumentRoot and ServerName for each vhost. You can use almost any directive that you can use in the main server configs in the vhost containers. You can make the DocumentRoot anything you want. It is general practice to create a directory that will hold all your virtual host directories. Then inside each of these directories create a sub-dir for the html pages (usually html or htdocs) and a cgi-bin. The DocumentRoot for each vhost would be its html sub-dir. Then ScriptAlias the cgi-bin so it will look like it is inside the DocumentRoot to the outside would. For example the url bar would read,
 
Thank you both for your suggestions. Quick question though, how would I create virtual hosts if I needed to install ssl, since name based wouldn't work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top