2

I would love to be able to use Python and Django for web applications at the company I work for. We currently use PHP because everyone is familiar with it and easy to deploy for a large number of clients. We can host anywhere between 10 to 100 websites on a single virtual server.

Is it possible to serve a number of websites from a single Apache and Python installation? Each website must have their own domain among other things, such as email accounts.

aychedee
  • 24,871
  • 8
  • 79
  • 83
  • 3
    Yes, it is possible. A quick Google search on this topic will turn up many answers to this question. – woemler Jan 22 '13 at 19:58
  • Use virtualenv to create "sandboxes" for each website, use Gunicorn or uWSGI to run the sites, use Nginx as front-end server and configure it to serve static content directly so you only hit the wsgi app for dynamic content. The details can easily be found using Google and some trial-and-error. – Daniel Eriksson Jan 22 '13 at 22:40

3 Answers3

3

I wouldn't use Apache, the current best practice is an Nginx frontend proxying requests to uWSGI servers. Read about the uWSGI Emperor mode. It's very versatile. http://uwsgi-docs.readthedocs.org/en/latest/Emperor.html. Each individual app can be modified, removed added to dynamically. We use it at PythonAnywhere to serve thousands of web applications

There are other WSGI servers that you can use as well. uWSGI just seems the most scalable in my experience.

aychedee
  • 24,871
  • 8
  • 79
  • 83
2

Yes, It is definitely possible. In our setup, typically we have django behind mod_wsgi, Apache and nginx

You can configure apache's Virtualhost, to point to a specific mod_wsgi which in turn points to specific code.

Quoting from here - Refer to the SO post for further information.

There are at least two methods you can try to serve from a single instance:

  1. Use apache + mod_wsgi and use the WSGIApplicationGroup and/or WSGIProcessGroup directives. I've never needed these before so can't be completely sure these will work the way you want, but regardless you can definitely use mod_wsgi in daemon mode to greatly improve your memory footprint.

  2. You can play with Django middleware to deny/allow URLs based on the request hostname (see HttpRequest.get_host() in the Django docs). For that matter, even though it would be a slight performance hit, you can put a decorator on all your views that checks the incoming host.

Community
  • 1
  • 1
karthikr
  • 97,368
  • 26
  • 197
  • 188
1

Yes, you can easily serve up many sites using a single Apache / mod_wsgi installation. Typically you would do that with a separate virtualhost section for each website. See the virtualhost docs. You want to use a different servername directive in each virtual host config to specify what hostnames get routed to which config. See more detailed documentation in name based virtual hosts

Anton I. Sipos
  • 3,493
  • 3
  • 27
  • 26