Forum Moderators: bakedjake

Message Too Old, No Replies

IP Based Hosting?

How do I get RH to serve pages by IP address too?

         

AprilS

9:54 pm on Jul 15, 2004 (gmt 0)

10+ Year Member



I'm pretty new to RedHat Enterprise as previously I've always used VPS servers running FreeBSD - which only had 1 vhosts.conf file for all vhosts.

However, on our new server I noticed all vhosts are separated into their own vhost files (new to me)... and I can go into the vhost files and add an alias for the IP address - but the server doesn't know to look into that particular vhost file for that IP address.

I'm missing a connection somewhere - I'm thinking it probably goes in the httpd.conf... but I don't know what to put there.

Any help would be greatly appreciated so I can access sites by IP as well as by domain name.

OH...also - side question - is it necessary to have all vhosts in separate files? I have multiple sites, but I'm the only one using our new dedicated.

MattyMoose

8:04 pm on Jul 16, 2004 (gmt 0)

10+ Year Member



Is possibly what you're thinking of an "include"?

I set up my sites like this (in httpd.conf):

NameVirtualHost *:80

include "/path/to/my/vhost.conf"
include "/path/to/my/othervhost.conf"

Is that what you mean?

encyclo

11:26 pm on Jul 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AprilS, can you post the section of the httpd.conf which calls the virtual hosts? (anonymize as required). I'd be surprised if it is neccessary to have separate files for each virtual host, as that is not the usual way with Apache and I've never seen it before.

Also, are you running Apache 1.3 or 2.0? Am I right in believeing RHES uses Apache 2.0 by default? Are you using the graphical administration tool or editing the files by hand?

The standard setup for virtual hosts is detailed here [httpd.apache.org], and I'm sure you know the reference guide [redhat.com] for Apache 2.0 on RHES already.

You might also want to check out the section of the Apache documentation called Dynamically configured mass virtual hosting [httpd.apache.org]: it might just be what you're looking for if you're setting up each virtual host in a /home directory. I've not tried it, but it looks promising as a method of managing the virtual hosts more easily as you don't need to set up each one individually.

AprilS

7:03 am on Jul 19, 2004 (gmt 0)

10+ Year Member



encyclo - I am currently using Apache 2. Also, all of my editing is being done from command line.

The online manual you referred me to "Dynamically configured mass virtual hosting" is for "Name" base hosting which allows you to have many domain names using a single IP address - which seems like what RH ES is already setup to do (name based hosting).

All of my domains will have their very own IP address - what I want to do is make it so I can access the site via IP address AND domain name - but currently, it seems like RH is setup (out of the box) to use name base hosting only.

----------------------------------------------
Here are snippets from my "httpd.conf" file that refer to vhosts

Include conf.d/*.conf
Include conf/vhosts/ssl
Include conf/vhosts/normal

-----------------------------------------------
Here is a sample vhost file in (conf/vhosts/normal)
conf/vhosts/normal/domain-name.com:80

NameVirtualHost *:80
ServerRoot /etc/httpd
<VirtualHost *:80>
ServerName domain-name.com
ServerAlias www.domain-name.com
ServerAlias 111.111.111.111
ServerAdmin webmaster@domain-name.com
DocumentRoot /home/domain-name/htdocs
LogFormat COMBINED
ErrorLog /home/domain-name/htdocs/logs/error_log
TransferLog /home/domain-name/htdocs/logs/access_log
</VirtualHost>

------------------------------------------------

This is a little different than I am used to with Apache on FreeBSD (first 3 lines are different).

Anyway, any clue why it is not serving pages by IP address. The only thing that comes up is the default Apache page (when there are no sites setup). One question you may ask is if it works by (domain name) - well, I don't know.... cause I can't switch our domains over until I KNOW this new server is working - so I have to work by IP address for testing. I've had the server for a week now and still can't test so any assistance would be GREATLY appreciated! :D

MattyMoose

5:21 pm on Jul 19, 2004 (gmt 0)

10+ Year Member



I think you'll need to do this:

NameVirtualHost 111.111.111.111:80
NameVirtualHost 222.222.222.222:80

ServerRoot /etc/httpd
<VirtualHost 111.111.111.111:80>
ServerName domain-name.com
ServerAlias www.domain-name.com
ServerAlias 111.111.111.111
ServerAdmin webmaster@domain-name.com
DocumentRoot /home/domain-name/htdocs
LogFormat COMBINED
ErrorLog /home/domain-name/htdocs/logs/error_log
TransferLog /home/domain-name/htdocs/logs/access_log
</VirtualHost>

<VirtualHost 222.222.222.222:80>
ServerName domain-name.com
ServerAlias www.domain-name.com
ServerAlias 222.222.222.222
ServerAdmin webmaster@domain-name.com
DocumentRoot /home/domain-name/htdocs
LogFormat COMBINED
ErrorLog /home/domain-name/htdocs/logs/error_log
TransferLog /home/domain-name/htdocs/logs/access_log
</VirtualHost>

The 111.111.111.111:80 rather than *:80 binds that VHost to a specific IP only, rather than listening on all IPs.

Although I don't think the ServerAlias IP.Ad.dr.ess is necessary.

Also, this might be answered more quickly if you also ask in the Apache forum.

-MM

AprilS

11:11 pm on Jul 19, 2004 (gmt 0)

10+ Year Member



MattyMoose - Thank you very much that did it!

encyclo

11:43 pm on Jul 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Include conf.d/*.conf
Include conf/vhosts/ssl
Include conf/vhosts/normal

Am I right in assuming that these includes are pointing to directories rather than files? Are your individual files then in these directories?

Looking at the Apache 2 documentation, I found this:

[httpd.apache.org...]

Specifically:

In addition, if Include points to a directory, rather than a file, Apache will read all files in that directory and any subdirectory. But including entire directories is not recommended, because it is easy to accidentally leave temporary files in a directory that can cause httpd to fail.

Try changing httpd.conf to read:

Include conf/vhosts/vhosts.conf

instead of the two virtual host directories, then place all your virtual hosts in the vhosts.conf file. Much easier than maintaining separate files for each!

AprilS

3:09 am on Jul 20, 2004 (gmt 0)

10+ Year Member



Correct - when I made the change MattyMoose selected I just commented out the "Include" lines. Right now I just left the VirtualHost definitions in the httpd.conf file - but when I move them to a vhosts.conf file I will include the "Include" statement again.

Thank you for all your help!

MattyMoose

4:13 pm on Jul 20, 2004 (gmt 0)

10+ Year Member



You're welcome. :)

I've often found it strange how RedHat modifies its httpd.conf from the standard one, but after a little digging, you can see the patterns. :)

Really all you'd need to do, if you wanted to set it up that each VHost has a different config file (sometimes useful), just create the files in "conf.d/", named like "vhost1.conf vhost2.conf" etc. They'll all be included automatically at the next restart/startup, due to the "Include conf.d/*.conf" line.

-MM