Tuesday, November 29, 2011

Nginx - How to configure the virtual.conf to serve a Django application

I'm trying to serve a Django application to production. I have
installed Gunicorn and now I need to setup a Nginx Virtual Host. I'm
kind of lost on how to configure the "virtual.conf" from Nginx. I just
want to use Nginx as proxy, I don't want to configure deplyment
scripts for now.

I have this layout taken from here(http://senko.net/en/django-nginx-gunicorn/):

server {
listen 80;
server_name example.com;
# no security problem here, since / is alway passed to upstream
root /path/to/test/hello;
# serve directly - analogous for static/staticfiles
location /media/ {
# if asset versioning is used
if ($query_string) {
expires max;
location /admin/media/ {
# this changes depending on your python version
root /path/to/test/lib/python2.6/site-packages/django/contrib;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://localhost:8000/;
# what to serve if upstream is not available or crashes
error_page 500 502 503 504 /media/50x.html;

To put things working I should replace:

root /path/to/test/hello;

For the path where I have my Django Project?

I have Django and all other Python scripts installed in a virtualenv.

Can someone give me some gidelines to get Django working with Gunicorn
with Nginx as proxy?

Best Regards,

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment