Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm used to Ubuntu, where there is a special file for containing the virtual hosts. But I'm getting the impression that in CentOS the virtual hosts are listed right in the main configuration file.

Can anyone confirm this?

EDIT - Tried this and it didn't work:

Added this to httpd.conf

<VirtualHost *:80>
       ServerName example.com
       ErrorLog /var/www/example_apache_errors.log
       DocumentRoot /var/www/html/example
       <Directory /var/www/html/example/>
               Options Indexes FollowSymLinks MultiViews
               AllowOverride All
               Order allow,deny
               allow from all
       </Directory>
</VirtualHost>

It did not work. The test page I created at /var/www/html/example/index.html is not showing up. Instead, the default page at /var/www/html/index.html is showing up.

EDIT: before anyone asks, yes, I'm restarting apache after ever config change.

EDIT:

NameVirtualHost *:80 is commented out by default in the config file and I didn't uncomment it. I believe that was the problem.

But I decided to use ip-based instead, like this:

<VirtualHost 69.175.xxx.xxx:80>
  ServerName example.com
  ServerAlias www.example.com

  DocumentRoot /var/www/example/

# etc. etc.

</VirtualHost>

And this is working. We have 5 ip's so hopefully I can use this method to assign others in the future.

share|improve this question
1  
You have "NameVirtualHost *:80" turned on? And "sudo apachectl configtest" is returning OK? –  cjc Jan 17 '12 at 3:32

2 Answers 2

up vote 4 down vote accepted

You know that you can just stick something like:

Include conf.d/*.conf
Include sites-enabled/*.conf

into /etc/httpd/conf/httpd.conf, run "mkdir -p /etc/httpd/sites-enabled /etc/httpd/sites-available" and get something similar to the Ubuntu directory structure for Apache, right?

Update (from information in comments):

You should verify that NameVirtualHosts for port 80 is turned on, also.

share|improve this answer
    
Yes, I know that now that you've told me and I will certainly try that if nothing else works. But what is standard practice on CentOS? I would rather not be too creative on the server config. I just want to do things the way they're usually done on CentOS if possible. –  Buttle Butkus Jan 17 '12 at 3:04
    
On my CentOS 5 box, I did an include of a virthosts.conf file which contained all my virtual hosts. On my CentOS 6, I'm following Ubuntu conventions, after a couple years exposure to how Ubuntu does things. I think as long as you document your changes and aren't insane about directory layout, it should be OK. I think it's much worse putting everything in the main httpd.conf file, for whatever my opinion matters. –  cjc Jan 17 '12 at 3:09
    
A separate file does seem more elegant. I will try that, but since I can't even get it to work inside the file I'm wondering if something else is wrong. –  Buttle Butkus Jan 17 '12 at 3:11
    
NameVirtualHost was commented out in the config file, so I think your comment was right on. Although, I did not test it because I ended up using ip-based VirtualHost instead. Your answer is good but I think you should add something about NameVirtualHost *:80 to it so I can give you the check mark. Thanks! –  Buttle Butkus Jan 30 '12 at 3:05
    
Updated with your suggestion. –  cjc Jan 30 '12 at 3:16

Since Centos has the Include conf.d/*.conf I place my configs there. However I typically have a conf.d/00_NameVirtualHost.conf with NameVirtualHost *:80. Im guessing you don't have that set in your apache config.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.