How to use Django on nginx+uwsgi

Hi all,

I'm currently planning to move a company website to django.

My background is primarily in PHP+MySQL although I've also written a couple thousand lines of code in python for offline apps. I'm not new to the linux shell either, but I am new to nginx and django.

I've deployed debian 5 and followed Python using uWSGI and nginx on Debian 5 from the linode library.

nginx is up and running (uploaded some static content to test it).

Since I'm new to django, I just started the tutorial -and now I'm stuck.

In the django tutorial, one of the first steps is starting the development server. I can do that on the server, but then i can't access the app.

What do i have to do to access the django app I'm creating with nginx instead of the django development server? There's just something I'm really not getting…

7 Replies

The django development server is for local development. I'd suggest you do your dev work locally.

Otherwise, you have bind it to the right ip and port. By default it only listens on 127.0.0.1 and uses port 8000. One or more of these may apply: 1) can't access 127.0.0.1 from your webbrowser, 2) you're not trying to access it using port 8000, or 3) firewall is blocking that port.

Oh, and I should repeat: do your dev work locally.

@sirpengi:

The django development server is for local development. I'd suggest you do your dev work locally.

That is correct, and I will do the development of the site locally, but i really wanted to check out how to move something i created locally to the server and be able to access it. Starting the django development server was more of a desperate try than anything else.

Keep your code in a versioning system. I'd recommend hg (mercurial), but the nerdy kids use git. You can get free accounts at bitbucket.org (for hg) or github.com (for git).

Keeping code in sync with your server is now basically tracking your repository.

If you use the right command line arguments with the dev server, you should be able to get access to it from the outside world. But I'd seriously suggest you consider reading about Django deployment ( http://www.djangobook.com/en/1.0/chapter20/ ) when that time comes.

If you're new to django, follow that tutorial you're using, and read the djangobook. It only took me a couple days to get down and dirty with django when I first started out.

@sirpengi:

By default it only listens on 127.0.0.1 and uses port 8000. One or more of these may apply: 1) can't access 127.0.0.1 from your webbrowser, 2) you're not trying to access it using port 8000, or 3) firewall is blocking that port.

I've used python manage.py runserver 0.0.0.0:8000 to start the dev server, and tried accessing it using port 8000, but it won't do.

The dev server is really not what i actually want to use, so i need to figure ou how to use nginx to access the app.

Ok, maybe i don't have to use nginx…

@sirpengi: would you recommend just using apache with mod_wsgi?

I personally run nginx+uwsgi, although now I'm thinking about gunicorn (not for performance reasons, just because of ease of deployment). You can find deployment guides for nginx+wsgi|uwsgi all over the net.

However, I'm also pretty fluent with my server distro and I can troubleshoot/fix issues/keep up to date with patches when they arise.

If you're not certain about what you're doing, or you're new to the server admin game, apache+modwsgi is probably your best bet because there are more resources out there. Also, the people that work on django recommend apache+modwsgi. It's time-tested and proven. Nginx+uwsgi is cutting edge stuff, so you might bleed a little.

I'll be switching over to apache + mod_wsgi. Otherwise I just have too many new variables at once.

Thanks!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct