Centos – Where to specify Apache2 Virtual Hosts in CentOS

apache-2.2centos

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.

Best Answer

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.

Related Topic