[CentOS] virtual host on latest centos 4.4

Will McDonald wmcdonald at gmail.com
Fri Oct 6 09:41:22 UTC 2006

On 06/10/06, Mark Fitzsimmons <Mark at xigen.co.uk> wrote:
> Good morning All,
> I have a slight issue with apache virtual hosts not working on my newly
> installed CentOS (4.4).
> I am very new to Linux, however I have experience with apache etc on
> 'w1nd0ws'. I've been round and round in the apache conf file and to no
> avail.
> Basically if I setup a virtual host the default then looks at it. Also,
> if I setup multiple virtual hosts they all look at the first virtual
> host.
> I'm running the machine inside my local network as a staging server for
> web design. I then set my HOSTS file on my PC to the ip of the server
> and then the www.domain.co.uk:
> Eg:
>   www.testsiteonvirtualhost.co.uk
> This is what I do on my other apache test server (not CentOS). I assume
> this should work??
> Is there anything other than virtual hosts that would need setting up??

Here's how I setup Name-based Virtual Hosts. Assuming a vanilla Apache
config, in /etc/httpd/conf/httpd.conf I add at the bottom...

# Individual sites' name-based vhost configurations are in
# /etc/httpd/conf.d/dev.*.conf
# NameVirtualHost for base site


# Define default catch-all vhost containers for requests
# which don't match any other containers defined in conf.d/

        ServerName webserv1
        DocumentRoot /var/www/html/


Then in /etc/httpd/conf.d/ I would have a file dev.site1.conf for
example containing

    ServerName      www.site1.co.uk
    ServerAdmin     webmaster at site1.co.uk
    DocumentRoot    /home/site1/public_html/
    RewriteEngine   on
    RewriteCond     %{REQUEST_METHOD} ^TRACE
    RewriteRule     .* - [F]
    ErrorLog    /home/site1/logs/error_log
    TransferLog /home/site1/logs/access_log
    CustomLog   /home/site1/logs/custom_log combined
    ScriptAlias /cgi-bin/ /home/site1/cgi-bin/
    <Directory "/home/site1/cgi-bin/">
        Options +ExecCGI

Copy and replace site1 for site2 in /etc/httpd/conf.d/dev.site2.conf and so on.


More information about the CentOS mailing list