Django Gunicorn Nginx Apache Php together

We develop a django site on the same server with a php

A lot of help came from the official Django documentation . Nginx is very usefull as Apache eats up a lot of memory. You can deploy Django on nginx using the gunicorn web server, while deploying Php using Apache.
Nginx in front of php, apache and django/gunicorn behind

Install nginx

Installing nginx couldn’t be simpler. Latest stable release is provided via a ppa repository.

Project structure

The user under which the app will run is webapp, so I checkout my app in /home/webapp.

Note that I’m using virtualenv to deploy this app.

Configure nginx and gunicorn

In your app dir create nginx.conf:

 

 

 

Next, I symlinked nginx.conf to the server’s sites-enabled directory.

This sets up nginx to directly serve the applications’s static files (css, js, etc.). Everything else is proxied to the gunicorn server.

Now gunicorn is a Python HTTP server. It’s super simple and effective. I installed it into the app’s environment.

create and edit:

vi gunicorn.conf.py:

The config files are simple and easy to read.

Running

I then collected all the static files into the static directory:

I restarted nginx:

And finally, I ran the gunicorn server:

Then

Apache

edit

Edit virtualhosts:

in

sudo /etc/init.d/nginx restart
sudo /etc/init.d/apache2 restart

Summarizing = static nginx port 80, dynamic Apache port 8080, dynamic Django port 8001.

Source =

http://honza.ca/2011/05/deploying-django-with-nginx-and-gunicorn

http://www.ibualoy.net/blog/itech/linux/167-how-to-configure-nginx-and-apache-on-debian