Preamble:
As promised in my last blog post this post is going to be all about how to set up a server to run Cherokee with uWSGI for deploying Django or other Python applications.
Server setup:
I am going to make some assumptions about your server environment:
- You are running Ubuntu 10.04 or similar. Older versions may have some changes that need to be made.
- This is a brand new server or VPS running at either Slicehost or The Rackspace Cloud. Other companies may work but I’ve only tested here.
- You have set the machine up, at least doing the steps here and here.
- You have a Django project you can deploy.
- You are running an operating system that is intelligent enough to give you a shell and open ssh tunnels.
Now that your server is set up you can run this shell script to install all of the software we will be using:
Yes I am installing Python modules server wide and no I don’t care about the problems that can come with that, since, I am only going to be running one application from this server. If you think you are going to have a problem with that install the python modules in the appropriate directories or sub-directories how ever you want to do that.
Now that everything is installed, let’s get it set up. Here are the steps:
- Set up our postgres username, password, and database. Here is a link to get setup.
- Copy your Django project to: /home/username/
- Sync your database
- Start the cherokee admin by running: cherokee-admin
- Open a second shell and run: ssh -l username -L 9090:localhost:9090 IPADDRESSFORYOURSERVER (Now you can go to localhost:9090 on your computer’s browser and get to the Cherokee admin interface.) You’ll need to use the username and password that come up from Step 4 above.
You can now start the Cherokee server by clicking the start server button (cool huh?) Once it is started follow the directions here:
http://www.cherokee-project.com/doc/cookbook_uwsgi.html
Edit your django_wsgi.py and uwsgi.xml files to match your application’s settings. Once that is done you should be able to start your site as long as things are correct. Oh, and don’t put your Django files in /var/www.
Configuration Options:
Here are some more configuration options:
1. Have the Cherokee server match multiple domains to the same virtual host:
- a. Serve your admin media:
b. Create a new rule as type Directory with the web directory being your admin media path (in this case mine is /media):
c. Change to the Handler tab choose Static Content and put the full path to your admin media in the Document Root including the trailing slash:
You can play with the other settings for it like gzip, deflate, and traffic shaping.
3. Change the user that the uWSGI process runs as, click Sources and select your uWSGI app:
I had to change this to the user where my code was deployed: /home/username/ for things to work correctly.
- Traffic monitoring. You can enable it by going to Status, then clicking on the virtual server, and checking enable at the bottom. You may need to choose RRDTool Graphs in General -> Network -> Information Collector:
- Looking at your log files if something isn’t working:
You just need to cat or tail /var/log/cherokee/cherokee.error. If you want it to log somewhere else you can configure it by clicking vServers -> your vServer -> Logging and changing the path there:
Tips and Tricks:
If you get something like:
uWSGI Error, wsgi application not found
Make sure that you have set the user that the uWSGI process runs as (step 4 in Configuration Options), save and hard restart the server.