22

Mar

Filed in Django, How-To's |

Recently I took the opportunity to configure my server for per-user hosting (to offer some free hosting to people who needed it). Doing this I had to configure mod_wsgi per-user as well. First, let me say that the documentation is excellent, but real world examples are always very helpful. Below is the output of a script which runs per-user on my server.

/etc/apache2/users/username.conf

<VirtualHost *>
	ServerAdmin username@localhost
	ServerName userdomain.com
	ServerAlias userdomain.com www.userdomain.com

	WSGIScriptAlias / "/home/username/.wsgi/project_name"
	WSGIDaemonProcess userdomain user=username threads=15 display-name=%{GROUP}
	WSGIProcessGroup userdomain

	DocumentRoot "/home/username/project_name"

	Alias /media/ "/home/username/project_name/media/"
	<Directory "/home/username/project_name/media">
		Order allow,deny
		Options Indexes
		Allow from all
		IndexOptions FancyIndexing
	</Directory>

	Alias /admin-media/ "/usr/local/django-dev/django/contrib/admin/media/"
	<Directory "/usr/local/django-dev/django/contrib/admin/media">
		Order allow,deny
		Options Indexes
		Allow from all
		IndexOptions FancyIndexing
	</Directory>

	<Directory "/home/username/project_name/">
		Options +ExecCGI
		Allow from all
	</Directory>

	ErrorLog /home/username/logs/userdomain.com/error.log
	CustomLog /home/username/logs/userdomain.com/access.log combined
</VirtualHost>

/home/username/.wsgi/project_name

import os, sys
 
# Add the project to the python path
sys.path.append('/usr/local/django-dev/django')
sys.path.append('/home/username')
 
# Set our settings module
os.environ['DJANGO_SETTINGS_MODULE']='project_name.settings'
 
import django.core.handlers.wsgi
 
# Run WSGI handler for the application
application = django.core.handlers.wsgi.WSGIHandler()
  • http://www.davidcramer.net/code/django/107/deploying-django.html Deploying Django | David Cramer’s Blog

    [...] Apache 2.x + mod_wsgiYou can see my configuration example. [...]

  • http://blog.dscpl.com.au Graham Dumpleton

    It is best not to include ‘processes=1′ option to WSGIDaemonProcess but let it apply its default of 1. This is because there is a subtle little difference between each. When it defaults to 1, wsgi.multiprocess is False, where as setting ‘processes=1′ results in wsgi.multiprocess is True. This distinction exists for where one may use a means of mapping across multiple process groups in same server, or requests are handled across multiple servers in a cluster. In other words, one needs a way of saying the application is logically hosted in a multiprocess setup even though only one process in that particular process group. I know it may be a bit non obvious, but best I could could up with at the time.

    Where does this matter? It matters if you want to use an in browser application debugger such as Paste EvalException or the one from Werkzeug. This will not work in a multiprocess setup as it relies on requests going back to the same process. In your setup the requests will go back to the same process, but debuggers such as EvalException think it is multiprocess setup and will not allow you to run it.

    So check out the ConfigurationDirectives document on mod_wsgi wiki as well as the DebuggingTechniques document.

    BTW, you might also look at the display-name option for WSGIDaemonProcess for mod_wsgi 2.0. Use that and ‘ps’ can be used to distinguish each users processes rather than them all appearing as being named ‘httpd’. Finally, you might also look at VirtualEnvironments document on wiki and setup things so that each user is working out of a Python virtual environment constructed using ‘virtualenv’. That way it is a lot easier for them to install their own Python packages.

  • David

    Thanks for the reply Graham. I’ll be changing the process count and the process name for sure :)

  • http://www.arnebrodowski.de/blog/ Arne Brodowski

    I use a combination of mod_wsgi and mod_vhost_alias to reduce apache config changes to a minimum for each new site.
    Per-site configuration (except for WSGIDaemonProcess directives) are written in a .htaccess file.

    I’ve documented the setup here (in german, but the listings should be readable) http://django-hosting.de/wiki/ApacheModWsgi/

  • David

    Arne, sounds like your method would work great for hosting multiple projects under the same domain.

  • http://jobscry.org jobscry

    dude, you rock. good info. had some problem with the admin media but turned out to be a permissions error.

  • thebattle

    Looks interesting!
    Thanks for letting us know about it.I really love your blog well done , congrats
    regards,
    share picture online

  • http://wildcat.arizona.edu hagan

    This may or may not be a problem in this example or even for most people but while I was setting up mod_wsgi and following along this example I noticed something that might be pitfall.

    If your django boilerplate code is stored under “/home/username/project_name”, as mine was, this configuration will allow apache to post any file in that directory. If this had been on the web and some script kiddie had found it, they’d have been able to read my settings.py file.

  • AliceWonderland42

    Thank you!

  • http://www.rochstgeorges.com Roch

    Do you know of anyway with htaccess to disable someone from using your domain to point to their own website on the same server? Ex: they use YOURDOMAIN.com to promote their PHISHING WEBSITE.COM by using this simple URL to send users : YOURDOMAIN.COM/~phishing/file.html

    Any help would be greatly appreciated. Thanks

  • http://www.chaneloutletstores.com chanel outlet

    It's wonderful to read about a female poet coming of age in this era, especially with Anne Sexton as a mentor for a short while, but so many other poetic luminaries as well. I'm also finding it encouraging to know, being 38 myself, that one can jumpstart her career at this age. Thank you for this inspiring interview, Julie Kane. http://www.Like-Acer.com
    write's unique point.It is useful and benefit to your daily life.You can go those
    http://www.chaneloutletstores.com

  • http://www.air-jordan-8.com/ air jordan 8

    Well , the view of the passage is totally correct ,your details is really reasonable and you guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum! http://www.globalcommuni-cation.com/

  • http://www.air-jordan-8.com/ air jordan 8

    Well , the view of the passage is totally correct ,your details is really reasonable and you guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum! http://www.globalcommuni-cation.com/

  • SandraMillhouse

    It depends. Don't you ask people to register an account? If you do, you delete their account.
    Sandra @ Cheap VPS

  • http://www.discount-coach-outlet.com coach outlet

    I am a gamer.When I come in the http://www.who-wanted.com post,Iloved it. Various pictures and perfect plot let me fall in love.If you love play game,you should come in.On the other hand ,there are some websites http://www.romantisongs.com content is very exciting,you can go and see.Like http://www.all-carefully.net

  • timberland shoes

    now,Timberlandlive is online store that professional supply best and newest timberland mens boots,Women timberland boots and Kid’s Timberland Boots and Shoes.We have over 10 years online shopping expeciences,our timberland shoes are no wonder your best choice,we promised to offer you genuince Timberland Boots uk,waterproof boots.We are firmly hold the “Customer is God” and “Your Satisfactions,Our Pursuit”princicals,we have a good Customer service teams and best after-service.We hope our professional can satisfy your requirments.Now cheap Timberland Boots sale,We have Timberland 6 Inch Boots,timberland uk,Timberland Chukka Boots and others 2010 newest Timberland work shoes for you!It’s a good chance to order now.Hope you have a good experience on shopping form us.

  • jordan shoes

    The air Jordan brand is a household name and people of all ages and social strata line up eagerly for the release of the latest model. Some of this success can be attributed to the fact that the shoes, from the Jordan III to the most recent model, have always started with their namesake, Michael Jordan. The designers take his ideas, hobbies, and life into account and incorporate these feelings into the air jordan shoes .The “jumpman” is the logo of jordan shoes.Now, we sell cheap jordan shoes. You can find wholesale jordan shoes.for example lebron james shoes ,kobe bryant shoes ,michael jordan shoes and so on, “Best Quality,Fast Delivery,Excellent Service”, this is the service spirit of our company.we have developed extensive contacts within many local and international freight organizations.Our Promises: Fast Delivery within 3-7 Days use EMS To Worldwide,Retail kevin durant shoes, nike air yeezy and air jordan 2010.Welcome to our homepage.

  • nike air max

    Nike Air Max is a timeless classic. Therefore, NIKE sportswear launched the Air Max shoes a lot of new products, mainly popular with Air Max 95, Air Max 90, nike air max 2009 and so on. One must mention the Air Max 90, Air Max 90 can be said is really the Air Max 1 Air Max has been on the return as a cultural shoes, Air Max 90 because of the appearance and the appearance of Air Max 1 serves the same purpose . At the same time increase the Air Max 90 Air Max 2009 and the thickness of the cushion, widen shoes, play a better stabilization effect.

  • http://www.mmbatteries.com laptop battery

    BTW, you might also look at the display-name option for WSGIDaemonProcess for mod_wsgi 2.0. Use that and ‘ps’ can be used to distinguish each users processes rather than them all appearing as being named ‘httpd’. Finally, you might also look at VirtualEnvironments document on wiki and setup things so that each user is working out of a Python virtual environment constructed using ‘virtualenv’. That way it is a lot easier for them to install their own Python packages.

blog comments powered by Disqus