Django rewrites URL as IP address in browser - why?
- by Mitch
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;