Monday, June 27, 2011

Re: Serving static/dynamic files under same suburl

Nginx can test to see if a file is available, and if it exist load that instead of proxying the request to django.


location / {
    alias /var/www/static/;
    if (!-f $request_filename) {
        proxy_pass http://127.0.0.1:8000;
    }
}

Now if /var/www/static/foo.js exists, but /var/www/static/bar.js does not foo.js will be served as a static file by nginx and the bar.js request will be passed to django where you can use a template to dynamically serve it.


Mick

On Monday, June 27, 2011 at 8:23 AM, Jani Tiainen wrote:

Apparently I didn't made myself clear enough.

So let me clarify:

I have two files that must be accessed using following urls:

/myapp/views/foo.js
/myapp/views/bar.js

foo.js is a static file and can (and should) be served by using static
serving, like webserver.

bar.js instead is a file that contains django template directives and
must be served through django template rendering mechanism.

On Jun 27, 5:14 pm, Shawn Milochik <sh...@milochik.com> wrote:
This can (and probably should) be handled by your Web server.

For example, in nginx you may be serving the Django app with something
like this:

     location / {
         proxy_passhttp://127.0.0.1:8400;
     }

And for static content nginx may direct the request elsewhere. This
example directs
any requests ending in '.html' to a static folder.

     location ~ ^/.*\.html{
         root /var/www/my_static_content;
     }

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

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