HTTP_HOST vs. SERVER_NAME

756 views
Skip to first unread message

janedenone

unread,
Aug 7, 2008, 10:42:40 AM8/7/08
to Django users
Hi,

in a CGI script, I used to use the SERVER_NAME environment variable to
get the domain used for a request. The hostnames are defined in /etc/
hosts for 127.0.0.1.

Now when I use the same variable in Django
(request.META['SERVER_NAME']), I always get 'literaturlocal' as the
server name – even though I use a different hostname to contact the
server. The HTTP_HOST, however, is correct (e.g. 'janlocal:8080'). Why
does the Django development server store 'literaturlocal' as the
SERVER_NAME?

- Jan

Malcolm Tredinnick

unread,
Aug 7, 2008, 10:50:43 AM8/7/08
to django...@googlegroups.com

It depends on the handler you're using, but Django basically stores
whatever the server passes along for that value. The only exception is
the modpython handler which uses the server_hostname value from the
modpython request (also not an unreasonable choice).

The behaviour also depends upon the web server and how it's configured
(for example, whether you have a ServerName directive in a virtual host
section in Apache).

Regards,
Malcolm


janedenone

unread,
Aug 7, 2008, 11:04:56 AM8/7/08
to Django users
Hi Malcolm,
Right, but I wonder why the WSGIServer picked up 'literaturlocal'. In /
etc/hosts, literaturlocal is just one element in a longer list, and
when I delete it and restart the dev server, another hostname from
that list gets picked arbitrarily. So requests for 'janlocal:8080/5'
and 'jakoblocal:8080/5' both cause request.META['SERVER_NAME'] to be
'literaturlocal'.

I cannot see the logic behind this.

Kind regards,
Jan
Reply all
Reply to author
Forward
0 new messages