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;

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 van Rees
"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
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment