Wednesday, November 30, 2011

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

On 29-11-11 21:05, Andre Lopes wrote:
> To put things working I should replace:
>
> [code]
> root /path/to/test/hello;
> [/code]
>
> For the path where I have my Django Project?

You won't even use that root. That's for serving regular static files
and that's only needed for the /static_media and /media urls in Django
(depending on how you set them).

So you need "locations" for your static stuff and a "/" location that
proxies to gunicorn.

I've got an example below. I start gunicorn on port 11000 in this case:


server {
listen 80;
client_max_body_size 1G;
server_name wgs.lizard.net;

keepalive_timeout 5;
access_log /Users/reinout/git/nens/wgs/var/log/access.log;
error_log /Users/reinout/git/nens/wgs/var/log/error.log;

location /static_media/ {
# django-staticfiles
alias /Users/reinout/git/nens/wgs/var/static/;
expires max;
# ^^^ Now that I give this example, I see that this 'max'
# probably only has to be on /static_media/CACHE/ ...
}

location /media/ {
alias /Users/reinout/git/nens/wgs/var/media/;
expires 24h;
}

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:11000;
}
}

Reinout

--
Reinout van Rees http://reinout.vanrees.org/
reinout@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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