DigitalJedi805
DigitalJedi805

Reputation: 1460

Can anyone explain why my virtual host setup in Apache is failing?

I have an Apache2 configuration under Cygwin that I'm in the process of setting up some virtual hosts for. The problem I am encountering is that regardless of the address entered, they all appear to be pointing to the same directory - which happens to be one of those virtual hosts.

My httpd-vhosts.conf is as follows ( Comments stripped ):

NameVirtualHost *:80

<VirtualHost sg.agpvideo.com:80>
    DocumentRoot "/home/user/public_html/sg.agpvideo.com"
    ServerName sg.agpvideo.com
</VirtualHost>

<VirtualHost rest.sg.agpvideo.com:80>
    DocumentRoot "/home/user/public_html/rest.agpvideo.com/laravel/public"
    ServerName rest.sg.agpvideo.com
</VirtualHost>

<VirtualHost site1.sg.agpvideo.com:80>
    DocumentRoot "/home/user/public_html/site1.sg.agpvideo.com"
    ServerName site1.sg.agpvideo.com
</VirtualHost>

<VirtualHost site2.sg.agpvideo.com:80>
    DocumentRoot "/home/user/public_html/site2.sg.agpvideo.com"
    ServerName site2.sg.agpvideo.com
</VirtualHost>

<VirtualHost agency1.sg.agpvideo.com:80>
    DocumentRoot "/home/user/public_html/agency1.sg.agpvideo.com"
    ServerName agency1.sg.agpvideo.com
</VirtualHost>

<VirtualHost agency2.sg.agpvideo.com:80>
    DocumentRoot "/home/user/public_html/agency2.sg.agpvideo.com"
    ServerName agency2.sg.agpvideo.com
</VirtualHost>

And it seems that all of them are pointing to the first in the list ( sg.agpvideo.com ). Does anyone have a simple explanation? If my httpd.conf is necessary I can post it.

Edit: In toiling with this trying to get it to work, a couple of them are pointing to the actual server's document root... Oddly enough.

Upvotes: 0

Views: 159

Answers (1)

Bryan Miller
Bryan Miller

Reputation: 3323

I'm not sure if this will completely solve your problem, but it might give you enough to figure it out. My setup (which works on my local Windows machine) is as follows. For each one of your subdomains, try replacing this:

<VirtualHost sg.agpvideo.com:80>
    DocumentRoot "/home/user/public_html/sg.agpvideo.com"
    ServerName sg.agpvideo.com
</VirtualHost>

with this in your httpd.conf file:

<VirtualHost *:80>
  ServerName  sg.agpvideo.com
  DocumentRoot "C:/xampp/htdocs/(whatever your project folder's name is)"
  <Directory "C:/xampp/htdocs/(whatever your project folder's name is)">
    Options All
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

and then, add an entry to your 'hosts' TCP/IP file located in your Windows folder (mine is 'C:\Windows\System32\drivers\etc\hosts'), add this:

127.0.0.1 sg.agpvideo.com rest.sg.agpvideo.com site1.sg.agpvideo.com (and so on)

If you need help with a production server setup, let me know and I can give you that setup as well.

Upvotes: 1

Related Questions