/admin redirects me to 127.0.0.1:8000/admin on nginx+gunicorn production server

881 views
Skip to first unread message

Daniel Oźminkowski

unread,
Jul 18, 2013, 2:08:33 AM7/18/13
to django...@googlegroups.com
Hello,

first I want to state, that I am a beginner and everything still works a little like magic for me. I have always worked with django by running it with runserver. Recently decided to put it on virtual machine and serve the site with nginx + gunicorn. I understand how to serve static files and so on. Even my app works. I hit the problem when I try to access built-in admin interface. Everytime when I go to http://VMip/admin I get redirected to http://127.0.0.1:8000/.

I made sure that SITE_ID is the same in settings.py and the django_site table.

The server is on a VM, I access it by ip. Here is my nginx config in sites-enabled/my_app.

server {
    server_name 192.168.0.112; # I noticed it doesn't matter. Nginx serves the site even if VM ip changes... hmmm?
    listen 80;

    root /home/daniel/www
    index index.html index.htm
    client_max_body_size 32M;
    client_body_buffer_size 128k;
    location /static/ {
        root /home/daniel/www
    }

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_connect_timeout 10;
        proxy_read_timeout 10;
        proxy_pass http://localhost:8000/;
    }
}

I will be very grateful for any clues how to fix it. Thanks!

Best regards,
Daniel

Daniel Oźminkowski

unread,
Jul 24, 2013, 4:32:21 PM7/24/13
to django...@googlegroups.com
Hello again,

I just had a WTF moment. I kept trying to access 192.168.1.4/admin which opened 0.0.0.0:8000 consistently for the last couple of hours (notice this is not localhost). Then I've read somewhere: "check with curl what kind of reponse you get directly from gunicorn". So I did and it was fine, I got the login form. Then I had a hunch - maybe it's something wrong with my browser, Chrome. Turns out I was right - it worked in incognito mode! I tried again with normal tab - again 0.0.0.0:8000. So I tried http://192.168.1.4/admin/ with the slash at the end and voila! Admin login form. Now even without the slash at the end I get the login form everytime.

Please, somebody explain this to me. I wasted so much time on this, tried so many nginx configurations and I still don't know what I did wrong. It's voodoo. ;)

Best regards,
Daniel Ozminkowski

2013/7/18 Daniel Oźminkowski <dozmin...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/ZbtZ9d8YPXo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Avraham Serour

unread,
Jul 24, 2013, 4:56:00 PM7/24/13
to django...@googlegroups.com

Well, if it works on incognito mode you should try cleaning your cookies

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Mike Doroshenko II

unread,
Jul 24, 2013, 5:39:30 PM7/24/13
to django...@googlegroups.com
I think this is a bug in Django. I am not using Nginx or Gunicorn and am also experiencing the same issue.

http://sandbox.junior.evandro.dev.tecknoquest.com/
On that page the "Customer Service Django App" link works with and without a slash at the end.

http://ballin.mikedoroshenko.com/
Backup copy of the site above (when I just purchased that domain and was playing around with DNS hence the ballin name lol). On that site clicking the same link on this site opens the user's browser to localhost instead of proxying. I get redirected to localhost without even seeing any output come up in terminal window for the dev server. Adding a slash makes it work fine.


Daniel Oźminkowski wrote:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
--
Mike Doroshenko, Junior Sys Admin
TecKnoQuest Inc.
mi...@tecknoquest.com
www.tecknoquest.com

Daniel Oźminkowski

unread,
Jul 25, 2013, 5:43:51 AM7/25/13
to django...@googlegroups.com
I thought that it may be connected to Chrome's Omnibox, but honestly now I can not replicate that behaviour. It works fine in and out of incognito mode.

Best regards,
Daniel Ozminkowski

2013/7/24 Avraham Serour <tov...@gmail.com>

Francisco Roldan

unread,
May 9, 2014, 2:41:43 AM5/9/14
to django...@googlegroups.com
Hi!, i have the same issue with nginx. When i try to access to /admin or another url without slash o when django redirects, nginx redirect to 127.0.0.1/admin.
How you solved?

Thanks, sorry my english

Daniel Oźminkowski

unread,
May 9, 2014, 3:26:22 AM5/9/14
to django...@googlegroups.com

Well, the whole description of how the error went away is down there in my emails.

Try to access the page with curl and/or incognito mode and see what response you get. Curl is a better choice, because you see all the details of the response. If you are on Windows and dont have curl, then use Chrome Developer Tools, they also tell you the details of the request.

Best regards,
Daniel Ozminkowski

Reply all
Reply to author
Forward
0 new messages