You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Giancarlo Rivas <gi...@gmail.com> on 2008/11/08 05:52:03 UTC

[users@httpd] VirtualHost / subdomain problems

Hi, I have a computer with windows xp32 behind a router that has apache
2.2.1.0. The router has a static ip and I configured it to redirect to the
computer that has apache. I also tested it works from a computer at a
different location, a basic "It works!" page can be requested.

I pointed a domain name to this static ip address. I created three
subdomains pointing to @, which means they all point to the same static ip
address. I tested from the remote computer and this works, the test page can
be retrieved.

I wanted to use virtual hosts so that if I typed the static ip address on my
browser, the server would respond as if it was a request to the root folder.

If I typed the domain name (no subdomain), the server would respond as if it
was a request to the root folder.

If I typed the domain name with a subdomain (one of them being www), the
server would respond as if it was a request to a SUBFOLDER, each subdomain
has a subfolder with the same name as the subdomain within htdocs, one
folder has a index.php file that contains phpinfo();, the other two are
empty.

No matter what I do I can only get all subdomain, domain and ip requests to
point to the root OR to the first subdomain folder I entered on httpd.conf,
all at the same time, so I am unable to achieve my objective.

File structure:
==========
F:/web/Apache2210/htdocs/
F:/web/Apache2210/htdocs/index.html -> "It works!"
F:/web/Apache2210/htdocs/subdomains/
F:/web/Apache2210/htdocs/subdomains/a/
F:/web/Apache2210/htdocs/subdomains/a/index.php -> "<?php phpinfo(); ?>"
F:/web/Apache2210/htdocs/subdomains/b/
F:/web/Apache2210/htdocs/subdomains/c/

Here is my latest configuration, I put this at the end of httpd.conf:
===============================================
<VirtualHost *>
DocumentRoot "F:/web/Apache2210/htdocs"
DirectoryIndex index.html
#index.html exists at that folder
</VirtualHost>
<VirtualHost *>
ServerName a.abcde.com
ServerAlias a.abcde.com
DocumentRoot "F:/web/Apache2210/htdocs/subdomains/a"
DirectoryIndex index.php
#index.php exists at that folder
</VirtualHost>
<VirtualHost *>
ServerName b.abcde.com
ServerAlias b.abcde.com
DocumentRoot "F:/web/Apache2210/htdocs/subdomains/b"
DirectoryIndex index2.php
#index2.php doesn't exist
</VirtualHost>
<VirtualHost *>
ServerName c.abcde.com
ServerAlias c.abcde.com
DocumentRoot "F:/web/Apache2210/htdocs/subdomains/c"
DirectoryIndex index3.php
#index3.php doesn't exist
</VirtualHost>
<VirtualHost *>
ServerName abcde.com
ServerAlias abcde.com *.abcde.com
DocumentRoot "F:/web/Apache2210/htdocs"
DirectoryIndex index.html
#index.html exists at that folder
</VirtualHost>

There are no typos on the censored domain/subdomain names, just checked
again.

For testing I tried to open:
===================
1. IP address
2. abcde.com
3. a.abcde.com
All three returned index.html
Then tried the other two subdomains and they return index.html.

If I change the order so that a.abcde.com's virtualhost is first then all my
results become index.php.

Yes, I save the config then reset apache.

NameVirtualHost
=============================
Originally I didn't have NameVirtualHost but now I have this line before the
virtualhost definitions:
NameVirtualHost <static ip address>:80

I can't seem to do what everyone can, I hope I am just missing something
simple.

Re: [users@httpd] VirtualHost / subdomain problems

Posted by Giancarlo Rivas <gi...@gmail.com>.
Thank you very much, it is working now.

On Sat, Nov 8, 2008 at 4:04 AM, Krist van Besien
<kr...@gmail.com> wrote:
> On Sat, Nov 8, 2008 at 5:52 AM, Giancarlo Rivas <gi...@gmail.com> wrote:
>
>> NameVirtualHost
>> =============================
>> Originally I didn't have NameVirtualHost but now I have this line before the
>> virtualhost definitions:
>> NameVirtualHost <static ip address>:80
>>
>> I can't seem to do what everyone can, I hope I am just missing something
>> simple.
>
> What you missed is that the value you give the NameVirtualHost
> directive must be identical to what you use in your <VirtualHost>
> blocks.
>
> So if your NameVirtualHost statement looks like this:
>
> NameVirtualhost 123.4.5.6:80
>
> Than your <VirtualHosts> blocks must start like this:
> <VirtualHost 123.4.5.6:80>
>
> Putting an IP address in the NameVirtualHost directive is usually not
> needed, and putting the static IP addres of the router in there is
> certainly not going to work. The only IP address that would make sense
> here would be the local address of the machine apache runs on. You
> usually don't need to worry about your apache server's internal
> address though.
>
> The best solution usually is to have this:
>
> NameVirtualHost   *:80
>
> <VirtualHost *:80>
> # First, default virtualhost.
> ...
> </VirtualHost *:80>
> <VirtualHost *:80>
> # Second host...
> ...
> <VirtualHost>
>
> and so on.
>
> To test things you can start apache like this:
>
> httpd -S
>
> This should list all the virtualhosts apache found in the config.
>
> HTH,
>
> Krist
>
>
> --
> krist.vanbesien@gmail.com
> krist@vanbesien.org
> Bremgarten b. Bern, Switzerland
> --
> A: It reverses the normal flow of conversation.
> Q: What's wrong with top-posting?
> A: Top-posting.
> Q: What's the biggest scourge on plain text email discussions?
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] VirtualHost / subdomain problems

Posted by Krist van Besien <kr...@gmail.com>.
On Sat, Nov 8, 2008 at 5:52 AM, Giancarlo Rivas <gi...@gmail.com> wrote:

> NameVirtualHost
> =============================
> Originally I didn't have NameVirtualHost but now I have this line before the
> virtualhost definitions:
> NameVirtualHost <static ip address>:80
>
> I can't seem to do what everyone can, I hope I am just missing something
> simple.

What you missed is that the value you give the NameVirtualHost
directive must be identical to what you use in your <VirtualHost>
blocks.

So if your NameVirtualHost statement looks like this:

NameVirtualhost 123.4.5.6:80

Than your <VirtualHosts> blocks must start like this:
<VirtualHost 123.4.5.6:80>

Putting an IP address in the NameVirtualHost directive is usually not
needed, and putting the static IP addres of the router in there is
certainly not going to work. The only IP address that would make sense
here would be the local address of the machine apache runs on. You
usually don't need to worry about your apache server's internal
address though.

The best solution usually is to have this:

NameVirtualHost   *:80

<VirtualHost *:80>
# First, default virtualhost.
...
</VirtualHost *:80>
<VirtualHost *:80>
# Second host...
...
<VirtualHost>

and so on.

To test things you can start apache like this:

httpd -S

This should list all the virtualhosts apache found in the config.

HTH,

Krist


-- 
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org