Weblog entry #1 for manojrane

virtual host returns 302
Posted by manojrane on Wed 12 Dec 2007 at 07:39
Tags: none.
<VirtualHost *>
ServerName my.domain.com
ServerAlias *.my.domain.com

UseCanonicalName Off

DocumentRoot /var/www/my.domain.com

ErrorLog /var/log/apache2/my.domain.com_error.log
CustomLog /var/log/apache2/my.domain.com_access.log combined

AddType application/x-httpd-php .php .mss

<Directory /var/www/my.domain.com>
Options -Indexes
</Directory>
<Directory /var/www/my.domain.com/conf>
Options -Indexes
Order Allow,Deny
Deny from all
AllowOverride None
</Directory>
</VirtualHost>


For this configuration of VirtualHost,

when I "telent my.domain.com 80"

It returns 200 OK and the page when request is sent as follows
"GET /index.html HTTP/1.0"

But it returns "HTTP/1.0 302 Found" when request is sent as follows
"GET http://my.domain.com/index.html HTTP/1.0"

Any clues why it does not return 200 when request includes the domain name?


(my.domain.com is added to hosts file on server as well as on my machine.)

 

Comments on this Entry

Posted by daemon (146.231.xx.xx) on Wed 12 Dec 2007 at 13:04
[ Send Message | View Weblogs ]

First thing -- do you have "NameVirtualHost *" in your apache config file above your first "" entry? If not you probably need it.

Secondly, is "my.domain.com" either a) the same as the real hostname of the box, and/or b) the first "" entry?

If you answered no to either of the above questions, then the problem is that you're not talking http 1.1 to the webserver, which you really need to to talk virtual hosts properly. Additionally, the GET verb in HTTP doesn't handle protocol prefixes and FQDNs (fully qualified domain names) at all.

So rather than:

GET http://my.domain.com/index.html HTTP/1.0

you need to telnet in and try this:

GET /index.html HTTP/1.1
Host: my.domain.com

(followed by hitting "Enter" twice) which should then work. The important bit is the "Host:" header, as otherwise, the server wouldn't know which virtual host the client was connecting to.

Cheers.
:wq

[ Parent | Reply to this comment ]

Posted by daemon (146.231.xx.xx) on Wed 12 Dec 2007 at 13:08
[ Send Message | View Weblogs ]

Oops, fingers making a mess of the markup. The first paragraph:

First thing -- do you have "NameVirtualHost *" in your apache config file above your first "" entry? If not you probably need it.

Should read:

First thing -- do you have "NameVirtualHost *" in your apache config file above your first "<VirtualHost *>" entry? If not you probably need it.

Dag-nabbit!
:wq

[ Parent | Reply to this comment ]

Posted by manojrane (203.129.xx.xx) on Thu 13 Dec 2007 at 04:20
[ Send Message | View Weblogs ]
Thanks for comments.

>>
telnet my.domain.com 80
GET http://my.domain.com:80/index.html HTTP/1.0
>>

This now works, but only after my.domain.com is added to DNS.
I was expecting that, when domain is added to /etc/hosts file (and since "ping my.domain.com' name resolved to IP properly on the server), apache will also resolve it if required.

I fail to understand that why hosts entry is not considered by Apache!

- Manoj

[ Parent | Reply to this comment ]

Posted by Nilshar (82.238.xx.xx) on Thu 13 Dec 2007 at 10:18
[ Send Message | View Weblogs ]
GET http://my.domaion.com
is just wrong.

In telnet, you have to give the host header as previous comment says.

telnet 127.0.0.1 80
GET / HTTP/1.1
Host: my.domain.com
<enter>
<enter>

Now you got what you want.


GET only takes URI.

[ Parent | Reply to this comment ]

Posted by manojrane (203.129.xx.xx) on Fri 14 Dec 2007 at 03:59
[ Send Message | View Weblogs ]
GET http://domain:port/path HTTP/1.0 is valid syntax (and is working fine).

See HTTP 1.0 RFC 1945 (http://www.w3.org/Protocols/rfc1945/rfc1945) section 3.2.2

It works after domain name is registered. I am trying to understand why it does not work when it is not registered but it is added to /etc/hosts file on the server. Why apache looks for external DNS resolution even when hosts file entry exist.

Also note, 1.0 does not support "Host:". I also tried with 1.1 & Host header, but result was same. It did not look in local host file :(

[ Parent | Reply to this comment ]

Posted by daemon (146.231.xx.xx) on Fri 14 Dec 2007 at 15:17
[ Send Message | View Weblogs ]

"Also note, 1.0 does not support "Host:". I also tried with 1.1 & Host header, but result was same. It did not look in local host file :("

That's why I suggested http 1.1.

Odd about 1.1 not working for you, it works for me, and I use it quite a lot. One point though, is the /etc/hosts file on the client or the server (or is it the same hardware)? When I use it, I have the hosts entry on the client (it's what's looking up the addresses anyway), and use HTTP/1.1. This is better for me because everyone in my section can test with a hosts file entry, without having to mess with central DNS unnecessarily.

Cheers.
:wq

[ Parent | Reply to this comment ]

Posted by endecotp (86.6.xx.xx) on Mon 17 Dec 2007 at 00:02
[ Send Message | View Weblogs ]
> GET http://domain:port/path HTTP/1.0 is valid syntax

No, I'm afraid it isn't, unless the server is a proxy server.

> See HTTP 1.0 RFC 1945 section 3.2.2

Have a look at section 5.1.2:

"The absoluteURI form is only allowed when the request is being made to a proxy."

> 1.0 does not support "Host:"

Correct. HTTP 1.0 does not support virtual hosts with a single IP address! This is one of the main differences between 1.0 and 1.1. See the introduction to HTTP 1.1 (RFC 2616):

... "HTTP/1.0 does not sufficiently take into consideration [...] virtual hosts."

> It works after domain name is registered.

My guess is that it thinks it is being used as a proxy, looks up the IP address to proxy to, discovers that it is itself, and then handles the request. But that's only a guess.

Phil.

[ Parent | Reply to this comment ]

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search