apache httpd virtual hosts setup keep hitting the same VirtualHost


 
Thread Tools Search this Thread
Operating Systems Linux Red Hat apache httpd virtual hosts setup keep hitting the same VirtualHost
# 1  
Old 05-25-2012
apache httpd virtual hosts setup keep hitting the same VirtualHost

I'm trying to set up two virtual hosts. Here's my httpd config:

Code:
<Directory /Users/userX/dev/sandbox-2>
    Order deny,allow
    deny from All
    Allow from localhost
</Directory>

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
    DocumentRoot "/Users/userX/dev/sandbox-2"
    ServerName blah                                                        
</VirtualHost>                     

<VirtualHost 127.0.0.1> 
    DocumentRoot "/Users/userX/dev/sandbox"
    ServerName fooboar
</VirtualHost>

My problem is that, no matter which server name I try to access in my browser (blah or foobar) it'll serve from blah's DocumentRoot. However, if I were to comment out the the VirtualHost for blah, then it'll take me to foobar's DocumentRoot.

I'm running apache2 on a mac osx if that makes a difference.

Thanks!

---------- Post updated 05-25-12 at 04:19 AM ---------- Previous update was 05-24-12 at 09:09 PM ----------

Here's the solution with the help of a member from another forum.

Code:
# default container
NameVirtualHost *:80
<VirtualHost *:80>
  DocumentRoot "/var/www/html"
  ServerName localhost
  <Directory "/var/www/html">
    Options FollowSymLinks
    AllowOverride None
  </Directory>
</VirtualHost>

# Virtual host 1
<VirtualHost *:80>
  DocumentRoot "/Users/userX/dev/sandbox"
  ServerName foobar
  <Directory "/Users/userX/dev/sandbox">
      Options Indexes FollowSymlinks MultiViews
      AllowOverride All
      Order allow,deny
      Allow from all
  </Directory>
</VirtualHost>

# virtual host 2
<VirtualHost *:80>
  DocumentRoot "/Users/userX/dev/sandbox-2"
  ServerName blah                                                        
  <Directory "/Users/userX/dev/sandbox-2">
      Options Indexes FollowSymlinks MultiViews
      AllowOverride All
      Order allow,deny
      Allow from all
  </Directory>
</VirtualHost>

But regarding about the errors that I had with the config that was posted:

There were multiple issues..

The biggest one is that I had a typo. (I had fooboar, not foobar)

Second, I need to include the port in NameVirtualHost as well as in

Also, what helped a lot while debugging this was start httpd in debug mode which is:

apachectl -e debug
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Apache/2.2.25 VirtualHost not working

I am having problems in implementing the virtual hosts here in my server. I have this one cloud dev server: Amazon Linux AMI release 2013.03 (based on RHEL like CentOS) with Apache 2.2.25 installed and I'm trying to create 2 virtual hosts: test-kalc.tk and test2-kalc.tk. If I go to... (2 Replies)
Discussion started by: jpdoria
2 Replies

2. Red Hat

apache 2.2 httpd.conf

Hi, I was wondering if someone could help me out here. I am super-paranoid, so am trying to limit what PHP files can be executed on this server. I have a small list of files that I want to allow. The rest, deny: <Files ~ "\.(php|php3)$"> order allow,deny deny from all </Files> I... (0 Replies)
Discussion started by: Lobster
0 Replies

3. Red Hat

apache 2.2 httpd.conf

Hi, I was wondering if someone could help me out here. I am super-paranoid, so am trying to limit what PHP files can be executed on this server. I have a small list of files that I want to allow. The rest, deny. So I have base rule that denies all php files server-wide: order allow,deny ... (0 Replies)
Discussion started by: Lobster
0 Replies

4. Web Development

Apache virtualhost dinternal domain

Hello, I have have installed two web applications on one server with one IP address and one domain name (mynet.intra). Is it possible to configure in apache 2.2 that access to one application would be from "app1.mynet.intra" and to another application from address "app2.mynet.intra"? Document... (1 Reply)
Discussion started by: kreno
1 Replies

5. UNIX for Dummies Questions & Answers

Maximum Number of Virtual Hosts per Apache instance

Is there a directive to limit the number of virtual hosts allowed per apache instance? I am told yes but I cannot find it. (1 Reply)
Discussion started by: mojoman
1 Replies

6. UNIX for Advanced & Expert Users

Building Apache httpd 2.2.15

Hi, What options should I use with ./configure to include mod_dav into the build? I use --enable-dav and I didn't see mod_dav.so anywhere in the build directory. I need to load mod_dav.so as a module during httpd startup. Thanks. (1 Reply)
Discussion started by: Parker_
1 Replies

7. Web Development

Apache: Forward Proxy Via Virtualhost

I've set up a forward proxy within a VirtualHost (see below) on Apache 2.2.11. I then browse using mydomain.com:80 as the proxy - I've also tried using the IP address of the VirtualHost xxx.xxx.xxx.xxx:80. It works fine, the only problem is that in both cases the server's main IP address is always... (2 Replies)
Discussion started by: krunksta
2 Replies

8. UNIX for Dummies Questions & Answers

Application & Virtual hosts in Apache

Folks; I need help knowing how to add an application to existing Virtual host on Apache. here's the details: I have a virtual host file (Based on IP address) for Apache and is configured to run application inside it. How can i add another application to the same virtual host based on the same IP... (0 Replies)
Discussion started by: moe2266
0 Replies

9. UNIX for Advanced & Expert Users

Apache 2 Virtual Hosts not resolving

Hey all, I'm having some apache problems. I've installed apache countless times on FreeBSD. However, I'm having some problems and I could use some help. Here is my system info: FreeBSD 5.2.1 Apache 2.0.51 (/usr/local/apache2), doc root (/www symlink to /var/www) PHP 5.0.1 (/usr/local/php)... (2 Replies)
Discussion started by: ezekiel61
2 Replies

10. UNIX for Dummies Questions & Answers

Apache httpd.conf <VirtualHost> issue

I have just configured httpd.conf on a new Redhat 9 install. Below are my additions to httpd.conf. Everything works fine except that when typing http://spetnik.d2g.com into my web browser, I am sent to the "Default catch all" site. Any clues? NameVirtualHost *:80 #Default catch all ... (5 Replies)
Discussion started by: Spetnik
5 Replies
Login or Register to Ask a Question

Featured Tech Videos