0
votes

Note: apparently there's a collision on the ServerName in my virtualhost entries and I need to make some changes to my /etc/hosts files. Looking into this but any insight is appreciated. Thanks

=======================================

(note I replaced http:// with hxxp:// to allow stackoverflow to let me post this)

I have a server, 10.1.1.1 that I am going to host multiple WordPress installations on in subdirectories. Specs on the server:

OS: RHEL 6.2 Santiago Apache version: Apache/2.2.15 (Unix) PHP version: 5.3.9 MySQL version 5.5.20

The first WordPress Installation I want to run from the virtual directory site_one (i.e. hxxp://10.1.1.1/site_one) -- the code for this site is to reside in /var/www/sites/site_one

The second WordPress Installation I want to run from the virtual directory site_two (i.e. hxxp://10.1.1.1/site_two) -- the code for this site is to reside in /var/www/sites/site_two

I have also dropped a dummy hello world index.html file in /var/www/sites

--

I have made the following changes to my httpd.conf:

  1. DocumentRoot for the entire site is set to /var/www/sites i.e.:

    DocumentRoot "/var/www/sites"

  2. at the very bottom of httpd.conf I have the following VirtualHost directives (I replaced < and > with [ ] because I couldn't get stack overflow to output < blocks >:

    NameVirtualHost *:80
    [VirtualHost *:80]
    ServerName 10.1.1.1
    DocumentRoot /var/www/sites/site_one
    Alias /site_one /var/www/sites/site_one/
    [/VirtualHost]

    [VirtualHost *:80]
    ServerName 10.1.1.1
    DocumentRoot /var/www/sites/site_two
    Alias /site_two /var/www/sites/site_two/
    [/VirtualHost]

    • I check the syntax of httpd (httpd -t) and the sytax is OK
    • I restart httpd

--

If I try to access hxxp://10.1.1.1/site_two it gives me a 404 and the error_log reports that it is looking in /var/www/sites/sites_one/site_two/ for the file... Obviously I want it to not look there but in /var/www/sites/site_two/ ... what am I doing wrong? Thanks for any and all help!

1
have you tried creating one vhost .conf file per vhost you want in /etc/httpd/conf.d/ instead of editing the main httpd.conf?scibuff
I think there is a conflict with the two references to port 80...matgargano

1 Answers

1
votes

See the Apache documentation. http://httpd.apache.org/docs/2.2/vhosts/name-based.html

You are trying to use Name Based Virtual Host because you only have one IP address. This is fine but you are missing the DNS part of how this works. From the documentation: "you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames."

The first listed virtual host is always the default host. That is why your site_one will behave the way you "think" it is supposed to, however when you try to access site_two, it falls under the default virtual host. You have the wrong idea about how Virtual Hosts work. What you are trying to do can be accomplished using aliases, however if anywhere in your code you refer to document root, you have to follow it up with which site you are referring to.

E.g. in PHP code something like this:

require($_SERVER['DOCUMENT_ROOT']."/site_one/directory/to/wherever