Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using django, nginx and apache. When I access my site with a URL (e.g., what appears in my browser address is the IP address with admin appended (e.g., When I access the site by IP, it is redirected as expected by django's (e.g., ->

I would like to have the name URL act the same way as the IP. That is, if the URL goes to a new view, the host in the browser address should remain the same and not change to the IP address. Where should I be looking to fix this?

My files:

; (apache)
NameVirtualHost *:8080

<VirtualHost *:8080>

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/htm

DocumentRoot /path/to/root

<IfModule mod_rpaf.c>
    RPAFenable On
    RPAFsethostname On

<Directory /public/static>
    AllowOverride None
    AddHandler mod_python .py
    PythonHandler mod_python.publisher

Alias / /dj
<Location />
    SetHandler python-program
      PythonPath "['/usr/lib/python2.5/site-packages/django', '/usr/lib/python2.5/site-packages/django/forms'] + sys.path"
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE dj.settings
    PythonDebug On



; ports.conf (apache)


; cpa.conf (nginx)
server { 

listen       80;

location /static {
    root   /var/public;
    index  index.html;

location /cpa/js {
    root   /var/public/js;

location /cpa/css {
    root   /var/public/css;

location /djmedia {
    alias "/usr/lib/python2.5/site-packages/django/contrib/admin/media/";

location / {
include /etc/nginx/proxy.conf;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


; proxy.conf (nginx)

proxy_redirect          off;
proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size    10m;
client_body_buffer_size 128k;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      500;
proxy_buffers           32 4k;
share|improve this question

Its probably your mod_rpaf config, I'm guessing the "RPAFsethostname On" line in particular.

I'm not fully confident because after googling for 10 minutes its clear that there is little to no documentation anywhere on mod_rpaf. It seems to be the kind of thing you would only ever hear about in a handful of "me and my fancy stack" blog posts. It solves a problem that you can just as easily solve in your django layer and not run some mystery apache module by some guy you read about on some blog post.

Its actually covered in the middleware chapter of the book:

share|improve this answer
Thanks for the suggestion. Removing the mod_rpaf stuff and including the middleware didn't change the behavior though. The mod_rpaf stuff does cause the remote IP address to be written to the apache log instead of – Mitch Aug 24 '10 at 1:55
Well in that case try futzing with this in – cagenut Aug 24 '10 at 14:21
I was able to resolve this. I think the fundamental problem was that my domain was not correctly registered with the DNS. – Mitch Aug 27 '10 at 13:57

Why even use nginx+apache+mod_python? Your stack is crazy and mod_python is horribly slow. Look into removing apache and running a wsgi server: I recommend uwsgi. I use it with nginx and django and it is wonderful!

I think you are just over complicating things.

share|improve this answer
Can you flesh this out a bit? Maybe explain why your opinion is better? – Scott Pack Apr 9 '13 at 13:16
ya take a look at – Mike Apr 9 '13 at 13:40
The idea of StackExchanges sites is to provide information directly, wherever possible As such is it preferable to include the essential parts of the answer here, and provide the link for reference. – Scott Pack Apr 9 '13 at 13:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.