• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • Last Modified:

I can't get VirtualHost set up correctly to show me a second domain.

I can't seem to get a VirtualHost to work.

I have httpd.conf that is running a site. It has a statements:
ServerName www.PrimaryDomain.com:80
DocumentRoot "/home/www/PrimaryDomain/root"
<Directory "/home/www/PrimaryDomain/root">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

... and a brief Rewrite section

Then,
NameVirtualHost 64.38.41.92:80
<VirtualHost 64.38.41.92:80>
         ServerAdmin support@PrimaryDomain.com
         DocumentRoot "/home/www/PrimaryDomain/root/"
         ServerName www.PrimaryDomain.com
         ServerAlias PrimaryDomain.com
         DirectoryIndex cgi-bin/index.pl
         ErrorLog "/home/www/PrimaryDomain/logs/VirtualHostError.log"
        <Directory "/home/www/PrimaryDomain/root">
        Options None
        Order allow,deny
        Allow from all
         </Directory>
      CustomLog "|/usr/sbin/rotatelogs /home/www/PrimaryDomain/logs/access_comb 604800" combined
</VirtualHost>
         
... and everything works fine.

But now I want the same server to run a second domain.  The second domain will serve only simple htm files.
I added this to httpd.conf:
<VirtualHost 64.38.41.92:80>
               ServerAdmin support@OTHER-domain.com
               DocumentRoot "/home/www/OTHER-domain/root/"
            ServerName www.OTHER-domain.com
            ServerAlias OTHER-domain.com
            DirectoryIndex HomePage.htm
            RewriteEngine off
               ErrorLog "/home/www/OTHER-domain/logs/VirtualHostError.log"
</VirtualHost>

When I go to http://www.OTHER-domain.com, the browser shows me the home page for the PrimaryDomain.

What's going on here?

Thanks for any help.





0
StevenMiles
Asked:
StevenMiles
  • 5
  • 5
  • 4
  • +1
2 Solutions
 
ryansinnCommented:
Apache 1 or Apache 2?

Basically Virtual host doesn't typically like the IP Binding...  You need to allow it to bind to anything when you start providing multiple Virtual Hosts because it's all the same IP and the same port (so you can't have things fighting to be first)

Use
<VirtualHost *:80>

Instead of the specific IP and this should work.
0
 
Dirtpatch-JenkinsCommented:
In your httpd.config file there will be an entry that looks like this

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

where # indicates a comment. if include conf/extra/httpd-vhosts.conf is commented change it to so ..

# Virtual hosts
Include conf/extra/httpd-vhosts.conf
0
 
fosiul01Commented:
1. do you have this line enabled
NameVirtualHost *:80

2.is there any reason that you have  same thign in 2 virtual host

ServerName www.PrimaryDomain.com:80   --------------------------------------------
DocumentRoot "/home/www/PrimaryDomain/root"
<Directory "/home/www/PrimaryDomain/root">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

... and a brief Rewrite section

Then,
NameVirtualHost 64.38.41.92:80
<VirtualHost 64.38.41.92:80>
         ServerAdmin support@PrimaryDomain.com
         DocumentRoot "/home/www/PrimaryDomain/root/"
         ServerName www.PrimaryDomain.com  -------------------------------------------------
         ServerAlias PrimaryDomain.com
         DirectoryIndex cgi-bin/index.pl
         ErrorLog "/home/www/PrimaryDomain/logs/VirtualHostError.log"
        <Directory "/home/www/PrimaryDomain/root">
        Options None
        Order allow,deny
        Allow from all
         </Directory>
      CustomLog "|/usr/sbin/rotatelogs /home/www/PrimaryDomain/logs/access_comb 604800" combined
</VirtualHost>

and also

3 .as ryansinn said

<<VirtualHost *:80>>
               ServerAdmin support@OTHER-domain.com
               DocumentRoot "/home/www/OTHER-domain/root/"
            ServerName www.OTHER-domain.com
            ServerAlias OTHER-domain.com
            DirectoryIndex HomePage.htm
            RewriteEngine off
               ErrorLog "/home/www/OTHER-domain/logs/VirtualHostError.log"
</VirtualHost>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
StevenMilesAuthor Commented:
Hi, yransinn,

Wow, fast answer.  It's 2.2.3
Here's what I did: I changed both <VirtualHost statements as you recommended, and I got the following notice when I restarted apache:
[root@server1 ~]# startsm
[Fri Feb 20 10:35:04 2009] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Fri Feb 20 10:35:04 2009] [warn] NameVirtualHost 64.38.41.92:80 has no VirtualHosts
When I tried to go to the PrimaryDomain, it didn't work, gave me a broken link notice
When I tried to go to the OTHER-domain, it gave me the PrimaryDomain's URL in the browser URL line, and of course it didn't work

So, trying something,  I changed
NameVirtualHost 64.38.41.92:80
to:
NameVirtualHost *:80

Then, there was no error notice when starting Apache, but the PrimaryDomain would not work as before, but the OTHER-domain worked fine!

Am I getting closer?
--Steve
0
 
ryansinnCommented:
The reason your first domain isn't showing up is because you're declaring it as the actual server and as a virtual host... if you're declaring the primary domain information outside of the first <VirtualHost *:80> section you have... just delete the primaryDomain virtual host... as it can't be both...

Hope that fixes it -- I routinely find I end up "tweaking" the apache2 config a bit before everything works 100%...

http://httpd.apache.org/docs/2.0/vhosts/name-based.html
0
 
StevenMilesAuthor Commented:
I seem to have run into this problem before. When I delete the primary domain's virtual host section, I got the following:
[Fri Feb 20 10:59:38 2009] [warn] NameVirtualHost 64.38.41.92:80 has no VirtualHosts

So, trying something again, I changed it to:
NameVirtualHost *:80
and there was no error message starting Apache, but both the PrimaryDomain and the Other-domain would show OTHER-domain's home page.  I can't get to the PrimaryDomain.

I promise I'm not trying to be obtuse here, just need a little more help.
--Steve
0
 
fosiul01Commented:
Hi, for last time can you past your virtual host here again please

let us have a look if your all configuraiton is ok or not
0
 
Dirtpatch-JenkinsCommented:
Do you have primary domain set as your document root in httpd?
0
 
ryansinnCommented:
You can go the other way ... comment out the DocumentRoot and ServerName from outside of the VirtualHost section and just declare everything within the VirtualHosts... that's what I do.

I also don't make any indication as to the server IP address anywhere in my configs.  I just use *:80 for all host information.

Declare the Primary VirtualHost with:

<VirtualHost _default_:80>
</VirtualHost>

and the rest with

<VirtualHost *:80>
</VirtualHost>

:)
0
 
StevenMilesAuthor Commented:
The link that ryansinn gave in a previous post of his indicates that there *should* be a VirtualHost container for PrimaryDomain.

Commenting out ServerName and DirectoryRoot where they sit *outside* of the VirtualHost container didn't help. The link seems to say that they will just be ignored.

Here's the current setup:
ServerName and DocumentRoot not commented out where they sit outside of the Virtual Host container.
NameVirtualHost *:80
<VirtualHost *:80>
               ServerAdmin support@PrimaryDomain.com
               DocumentRoot "/home/www/PrimaryDomain/root/"
               ServerName www.PrimaryDomain.com
               ServerAlias PrimaryDomain.com
               DirectoryIndex cgi-bin/index.pl
                 ErrorLog "/home/www/PrimaryDomain/logs/VirtualHostError.log"
              <Directory "/home/www/PrimaryDomain/root">
              Options None
              Order allow,deny
              Allow from all
         </Directory>
              CustomLog "|/usr/sbin/rotatelogs /home/www/PrimaryDomain/logs/access_comb 604800" combined
</VirtualHost>

<VirtualHost *:80>
               ServerAdmin support@OTHERDomain.com
               DocumentRoot "/home/www/OTHERDomain/root/"
            ServerName www.OTHERDomain.com
            ServerAlias OTHERDomain.com
            DirectoryIndex HomePage.htm
            RewriteEngine off
               ErrorLog "/home/www/OTHERDomain/logs/VirtualHostError.log"
</VirtualHost>

The PrimaryDomain can't be accessed in the browser.
The OTHERDomain seems to work fine.

--Steve

0
 
fosiul01Commented:
your virtualhost setting looks allright to me


in your first comment you had another virtual host with same domain(www.PrimaryDomain.com),

do you have still that one in apache.conf file or did you deleted that one ??

when you type :www.PrimaryDomain.com, does it go to other domain or it does not comeup totaly ??

0
 
Dirtpatch-JenkinsCommented:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    DocumentRoot "C:/where/primary/is"
    ServerName primaryhost.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/where/secondaryfolder/is"
    ServerName dummyhost.com
</VirtualHost>


thats stripped down...but works.
0
 
ryansinnCommented:
Looking at my conf -- I don't declare ServerName where I'm using ServerAlias... I just put all domains in the ServerAlias line.

Are you declaring "BindAddress" anywhere in your config files, httpd.conf, apache.conf or sites-enabled/*   ?

Can you simply your two domain entries to the following:



And then clear /create the log file... restart apache... and post the results of the log file.

NameVirtualHost *:80
 
<VirtualHost *:80>
DocumentRoot /var/www/mydomain
ServerAlias www.domain.com domain.com
CustomLog /var/log/apache2/mydomain.log combined
</VirtualHost>
 
<VirtualHost *:80>
DocumentRoot /var/www/seconddomain
ServerAlias www.seconddomain.com seconddomain.com
CustomLog /var/log/apache2/seconddomain.log combined
</VirtualHost>

Open in new window

0
 
StevenMilesAuthor Commented:
Hi, ryansinn,
When I make the changes you ask for, stripping down the virtual host containers, I can't access the secondary domain, but it doesn't show up as a broken link, rather it gives me the "Forbidden" page, "You don't have permission to access / on this server."

 and here is what is in the log for secondary, lines exactly like this:
70.184.223.98 - - [20/Feb/2009:13:30:18 -0600] "GET / HTTP/1.1" 403 289 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"
70.184.223.98 - - [20/Feb/2009:13:30:20 -0600] "GET / HTTP/1.1" 403 289 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"

When I try to access the primary site, it shows me the *secondary* site instead. Here is an excerpt from the *primary* log file:
::1 - - [20/Feb/2009:13:30:07 -0600] "GET / HTTP/1.0" 200 252 "-" "Apache/2.2.3 (Red Hat) (internal dummy connection)"
::1 - - [20/Feb/2009:13:30:07 -0600] "GET / HTTP/1.0" 200 252 "-" "Apache/2.2.3 (Red Hat) (internal dummy connection)"
70.184.223.98 - - [20/Feb/2009:13:30:13 -0600] "GET / HTTP/1.1" 304 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"
70.184.223.98 - - [20/Feb/2009:13:30:15 -0600] "GET / HTTP/1.1" 304 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"
70.184.223.98 - - [20/Feb/2009:13:30:15 -0600] "GET /images/case_arrow_right.gif HTTP/1.1" 304 - "http://www.stockmonitor.com/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"
70.184.223.98 - - [20/Feb/2009:13:30:15 -0600] "GET /images/HomeCellAndHand_3.jpg HTTP/1.1" 304 - "http://www.stockmonitor.com/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"
70.184.223.98 - - [20/Feb/2009:13:30:15 -0600] "GET /images/SignUpNow_140flat.jpg HTTP/1.1" 304 - "http://www.stockmonitor.com/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"

I should also say that there is an nss.conf that is listening in on port 443, and going to https://www.PrimaryDomain.com works filne.

Also, using "<VirtualHost _default_:80>" didn't change anything for me.
--Steve


0
 
StevenMilesAuthor Commented:
I got it working.  I don't know why, but I do know how.
Looking at the logs, there was some problem with the OTHERDomain undergoing rewrites that were supposed to happen only for the Primary domain, even though there was the line:
RewriteEngine off
in the OTHERDomain <VH block.

I moved the Rewrite section into the PrimaryDomain VH block. I couldn't access the Primary domain then, because the rewrites weren't happening.  That's what I had seen before, where I needed the Rewrites outside of the VH blocks.

But then I took the IP address out of the NameVirtualHost and VirtualHost statements, using *:80, and now the whole thing seems to work: Both domains, rewrites.

I even added *another* domain, and now all three are working.
--Steve
0
 
Dirtpatch-JenkinsCommented:
Glad to hear it, as above poster stated, setting up virtual hosts for the first time rarely go off without a hitch.

0
 
ryansinnCommented:
hmm... maybe change combined on the log line to error -- so we can just see the errors... there had to be something throwing an error during the process.  The syntax of the apache config must have been correct otherwise Apache typically doesn't start.

I'm glad everything is working for you... sorry I couldn't provide you with a more definitive solution.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now