I'm writing a django app that will be used in a LAN environment. The
server typically does not have a domain name configured and is
accessed via the IP address.
In such a setup, I'm getting
HTTP_HOST: 192.168.1.20:4334
SERVER_NAME: localhost
The app uses the django.contrib.syndication module to provide some RSS
feeds. This module uses SERVER_NAME to generate the links for the
items. Since it's value is localhost, the links do not give the right
address if the feed is read on another computer. But it works properly
if HTTP_HOST is used.
So the question is, whats the difference between these two, and should
the syndication module be using HTTP_HOST?
--
Siddharta Govindaraj
http://siddhi.blogspot.com
Assuming you're deploying on Apache with mod_python, have you tried
setting ServerName in your httpd.conf to someting sensible?
Ciao,
- Matthias
Hi Mathias,
The app is being deployed using Toolserver for Python and it's hooking
up to Django via WSGI. The deployment scenario is that each team will
run the app on a team computer that will be accessed by 10-20 people
in the team via the IP address.
--
Siddharta Govindaraj
If you are using WSGI interface to Django, then all you need to do is
wrap Django in a simple WSGI application wrapper that overrides
SERVER_NAME and sets it to what you want. For example:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
environ['SERVER_NAME'] = environ['HTTP_HOST']
return _application(environ, start_response)
If you don't understand WSGI and how this works, check out 'http://
www.wsgi.org'.
Graham
Hi Graham,
Thanks, thats one good option.
I'm still confused about the difference between HTTP_HOST and
SERVER_NAME. Is it that one has the IP and the other has the name?
--
Siddharta Govindaraj
HTTP_HOST is what the client sends in the 'Host' request header and
should really be what was used as the host in the URL.
SERVER_NAME on the other hand is what the server believes is it host
name.
If a server had numerous aliases, then one could see different names
in HTTP_HOST which would all be valid, but SERVER_NAME would always be
the same value.
In practice this is a rather simplistic explanation as there is a lot
more to it than that, and the value of HTTP_HOST can be affected by
the presence of proxies and the version of the HTTP protocol being
used.
By rights you should be doing what you can to ensure that SERVER_NAME
is correct in the first place. As already suggested, if one was using
Apache, that would mean setting Apache ServerName directory to the IP
address of the machine if it doesn't have a proper host name that
clients identify it as.
Since you are using ToolServer, tell it somehow to use the IP address
instead of 'localhost' as the server name. This may be part of how you
tell it what host to listen on for socket connections.
Graham