Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using django, nginx and apache. When I access my site with a URL (e.g., http://www.foo.com/) what appears in my browser address is the IP address with admin appended (e.g., http://123.45.67.890/admin/). When I access the site by IP, it is redirected as expected by django's urls.py (e.g., http://123.45.67.890/ -> http://123.45.67.890/accounts/login/?next=/)

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:

; cpa.com (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
ServerName www.foo.com

<IfModule mod_rpaf.c>
    RPAFenable On
    RPAFsethostname On
    RPAFproxy_ips 127.0.0.1
</IfModule>

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

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
</Location>

</VirtualHost>

;

; ports.conf (apache)
Listen 127.0.0.1:8080

;

; cpa.conf (nginx)
server { 

listen       80;
server_name  www.foo.com;

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_pass   http://127.0.0.1:8080;
}
}

;

; 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
add comment

2 Answers 2

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: http://www.djangobook.com/en/2.0/chapter17/

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 127.0.0.1. –  Mitch Aug 24 '10 at 1:55
    
Well in that case try futzing with this in settings.py: docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url –  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
add comment

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!

http://projects.unbit.it/uwsgi/

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 nichol.as/benchmark-of-python-web-servers –  Mike Apr 9 '13 at 13:40
1  
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
add comment

Your Answer

 
discard

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.