Here is an installation guide for Nginx + uWSGI. You can run these commands individually, or you can paste them into a shell script and run it as
Either way, you may want to run it in a screen session. First, create a new Custom Application (listening on port), and note the assigned port. If you don't have a Django application (or other WSGI-compatible app) already, create one also. Then, fill in the appropriate variables at the top of this script.
Then, to start the stack, use:
And to stop it, you have:
answered 19 Aug '12, 01:47 ryans ♦♦ How do I write a script, if I use virtualenv?
(17 Jan '13, 08:07)
rendrom
1
I'm fairly sure this guide is orthogonal to virtualenv, because any applications or scripts you run would implement the virtualenv environment via
(17 Jan '13, 20:51)
ryans ♦♦
How much memory improvement do you see by setting up Django this way vs. configuring Django via the Webfaction control panel?
(21 Feb '13, 22:32)
ehutch
@ehutch there is not necessarily a memory usage improvement; it really depends on the Django application.
(22 Feb '13, 01:33)
waynek
|
Here is a 2014 update along with instructions for using virtualenv. I just successfully installed Nginx 1.4.7 with uwsgi 2.0.3 using a script loosely based on the script by RyanS. I did not create a Django app as mentioned by RyanS. I did create the custom port. I removed the DJANGOAPP and DJANGOPROJECT variables from the script. I also removed this section:
This section creates the wsgi.py. I did not need it because I already had one in my Django project. In RyanS's script he shows you where he got the nginx and uwsgi code. Then in the script he has you get the code from a mirror. You can just replace the wget's to the mirror with wget's directly to nginx.org and projects.unbit.it. Next I ran the script using the command Ryans gave. It installed without a problem! To link the app with my Django code, I made a symbolic link to wsgi.py in my Django code base. Here is my wsgi.py code that fires up virtualenv:
I should also mention that I created a website from this app by linking it to a domain name using the Webfaction Control Panel. As for memory usage, it was about half that of the same Django code running under Apache and mod_wsgi. No noticable difference in performance. However, my websites have very low volume. I probably am not taking advantage of nginx's strengths. How am I going to setup my next website? Given how smooth the nginx and uwsgi install was, I will go with nginx. answered 22 Apr '14, 17:43 cwurld2 How does nginx/uwsgi get restarted if the server reboots? Does it automatically run every app's bin/start on boot up?
(02 May '14, 08:15)
pcglue
Typically you should have a cron job that tries to start your backend server every 20 minutes like the example below. 4,24,44 * * ~/webapps/$APPNAME/bin/start You also can have a cron entry that starts the process at boot time of the server.
(02 May '14, 12:20)
aaront ♦♦
@aaront, @ryans, Great posts, I got this to work by manually running the commands in the script but if I try bash -e build_uwsgi.sh | tee build_uwsgi.log, I get ": command not found:" I tried adding "#!/bin/sh" at the top, but no effect. The variable assignment lines work fine. Its getting caught up at some point after, the blank line or the mkdir line. the .log file is empty. any thoughts?
(29 Oct '14, 23:05)
rsp
@rsp I've looked through your home directory and I don't see your
(29 Oct '14, 23:46)
seanf
@seanf where to get build_uwsgi.sh ?my account is patchserver2 update: found it below!
(17 Dec '14, 08:52)
lifepatch
Hi, How did you make a "symbolic link to wsgi.py in my Django code base"?? I'm almost there. Just need to figure this out. :)
(09 Jun '15, 14:50)
Rijo John
@Rijo John - there's no need to follow this manual procedure. There's a one-click install available here: web2py + nginx + uwsgi installer for WebFaction That said, if you want to make a symlink, you do that with the
(09 Jun '15, 15:30)
seanf
Thanks Sean, does it work for Django too?
(09 Jun '15, 15:34)
Rijo John
Oh, snap. I missed that part of your question :\ No, the installer that I linked is only for web2py.
(09 Jun '15, 15:42)
seanf
It's fine, your symlink helped! Everything working excellently :D Thanks :)
(10 Jun '15, 03:49)
Rijo John
showing 5 of 10
show 5 more comments
|