[help] Server Config: django + uwsgi + nginx

585 views
Skip to first unread message

easypie

unread,
Apr 29, 2012, 1:49:32 PM4/29/12
to django...@googlegroups.com
I have this file that was created for me by one of the users in django's irc channel. I edited to have the right information inserted but I"m not sure what I'm doing wrong to not make it work. I've spent some time trying to understand each line by searching the web. There's still a thing or two that's missing from the puzzle. Maybe it's the server config that has a flaw or the way I went about it. I haven't done a fresh install of uwsgi and nginx yet. However, please take a look to see if there's an error or solution that could work. Thanks.

Roberto De Ioris

unread,
Apr 29, 2012, 2:31:43 PM4/29/12
to django...@googlegroups.com
I suggest you to not start with such a complex scenario.

I would go step-by-step with a very simple setup involving only uWSGI:

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

Then, change the http protocol to the uwsgi one (simply replace http =
with socket = ) and put it behind a simple nginx config (like the one you
will find following the uWSGI quickstart).

Then move to the 'upstart' part, adding the script to the /etc/init
directory.

Finally start playing with caching (it can be the most challenging part)

--
Roberto De Ioris
http://unbit.it

Karl Sutt

unread,
Apr 29, 2012, 3:01:27 PM4/29/12
to django...@googlegroups.com
Here is my uWSGI command and nginx.conf contents:


I've used it for a Flask application, but I've just tested it and it works for a Django project as well. Note that wsgi.py file in the uwsgi command is the Python file that Django generates when you first create a project, there is no need to change it.

Good luck!

Karl Sutt


On Sun, Apr 29, 2012 at 6:49 PM, easypie <progr...@gmail.com> wrote:
I have this file that was created for me by one of the users in django's irc channel. I edited to have the right information inserted but I"m not sure what I'm doing wrong to not make it work. I've spent some time trying to understand each line by searching the web. There's still a thing or two that's missing from the puzzle. Maybe it's the server config that has a flaw or the way I went about it. I haven't done a fresh install of uwsgi and nginx yet. However, please take a look to see if there's an error or solution that could work. Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/2rekHP0I6V0J.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

easypie

unread,
Apr 30, 2012, 1:19:14 AM4/30/12
to django...@googlegroups.com, rob...@unbit.it
i followed the django-http+uwsgi quick start and ended up with an error. ImportError: no module named django.core.handlers.wsgi \n unable to load app ...
here's the error log: dpaste.org/BM5BW

Roberto De Ioris

unread,
Apr 30, 2012, 2:15:52 AM4/30/12
to django...@googlegroups.com, rob...@unbit.it

> i followed the django-http+uwsgi quick start and ended up with an error.
> ImportError: no module named django.core.handlers.wsgi \n unable to load
> app ...
> here's the error log: dpaste.org/BM5BW

Are you sure you are not using a >=1.4 django version or a virtualenv ?

If you are uging a virtualenv, add

virtualenv = <path>

to the uWSGI config file
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/73nF9MjDBvYJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


easypie

unread,
Apr 30, 2012, 2:04:26 PM4/30/12
to django...@googlegroups.com
does your configuration allow for running multiple sites?
Good luck!

Karl Sutt


To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

Karl Sutt

unread,
Apr 30, 2012, 7:36:05 PM4/30/12
to django...@googlegroups.com
I am not entirely sure what you mean by that. If you mean the nginx equivalent of Apache VirtualHosts then the nginx wiki explains it quite nicely http://wiki.nginx.org/ServerBlockExample. Is that what you meant?

Karl Sutt


To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/sMsRN5iG9NQJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.

Kurtis Mullins

unread,
May 1, 2012, 11:04:00 AM5/1/12
to django...@googlegroups.com
Judging from your Import Error -- I think you're having a problem with Django not being on the Python path. In my uwsgi configuration file (I used .xml), it looks like this:

<uwsgi>
    <master/>
    <env>DJANGO_SETTINGS_MODULE=fireflie.settings</env>
    <processes>4</processes>
    <socket>0.0.0.0:7999</socket>
    <chdir>/home/fireflie/staging/fireflie/</chdir>
    <module>django.core.handlers.wsgi:WSGIHandler()</module>
    <pythonpath>/home/fireflie/staging/fireflie/</pythonpath>
    <pythonpath>/home/fireflie/staging/</pythonpath>
    <daemonize>/var/log/uwsgi/uwsgi.log</daemonize>
    <pidfile>/tmp/fireflie-staging.pid</pidfile>
</uwsgi>

Note: That's not guaranteed to be production-ready (we're just using it for development) and I'm also not using a virtual environment (we use a whole sever for the single Django application). In other words, I'm not following best practices by a large margin. Good luck!

easypie

unread,
May 2, 2012, 1:28:34 AM5/2/12
to django...@googlegroups.com
how would i start that?
sudo uwsgi start
sudo service nginx start?


On Sunday, April 29, 2012 12:01:27 PM UTC-7, Karl Sutt wrote:
Good luck!

Karl Sutt


To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

easypie

unread,
May 2, 2012, 1:31:19 AM5/2/12
to django...@googlegroups.com
Thanks. I was missing the virtualenv=<path> mentions earlier. I'm glad I know this those settings are meant for development only. I was a little confused thinking that was ready for deployment. I'm new to all this and get confuse sometimes.

Kurtis Mullins

unread,
May 3, 2012, 1:22:54 PM5/3/12
to django...@googlegroups.com
Hey, I'm glad to hear you got it working! If you run into any more problems, don't hesitate to ask.

To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/cPvZyCPXPNUJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.

easypie

unread,
May 3, 2012, 5:23:12 PM5/3/12
to django...@googlegroups.com
I'm not sure if I should post this in this thread of mine or start new one. But it's still about the config files.

After getting uwsgi to work. I tried to link nginx w/ it but that didn't work. I go to localhost:80 and that takes me to the welcome page: "Welcome to Nginx!". When I go to localhost:8000 (which I want), it doesn't load (unable to connect). Please take a look at the code: http://dpaste.org/oIjP9/

Karl Sutt

unread,
May 3, 2012, 5:40:35 PM5/3/12
to django...@googlegroups.com
Have you symlinked /etc/nginx/sites-available/mysite.com to /etc/nginx/sites-enabled/mysite.com ?

Karl Sutt


To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/lU_hOfkWep0J.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.

easypie

unread,
May 3, 2012, 6:52:56 PM5/3/12
to django...@googlegroups.com
yes. i believe it's 'ln -s /etc/nginx/sites-available/mysite.com /etc/nginx/sites-enabled/mysite.com'
Reply all
Reply to author
Forward
0 new messages