Monday, January 30, 2012

Re: Django Deploy - Some Questions regarding it

I don't know much about nginx, but here are some pointers:

First, this page seems good source of information:
https://code.djangoproject.com/wiki/DjangoAndNginx

Now, take note of the "location /site_media" directive in the above
link. This is basically telling the server that when there is a
request for localhost/site_media/some_file then check some_file from /
media. This is the main point here. You are serving the media from
filesystem path /media, and it is accessible from the www.somesite.com/site_media/
URL. I don't know about nginx, but it is probably crucial that the
location site_media is _above_ the other location directives.

If you are able to serve some static files from site_media/ path and
Django from root path you are close to solution. Then, using the above
example where /site_media was mapped to filesystem path /media, you
will need to actually have the media files under /media/ file system
path. This is best done using Django's static media application. You
also need to tell Django to upload the files to /media directory.
Check Django's uploading files documentation for how to do this.
Helping links:
https://docs.djangoproject.com/en/dev/howto/static-files/
https://docs.djangoproject.com/en/dev/topics/http/file-uploads/

Sorry if some/all of the above is obvious to you. You have so many
questions packed in one post that it is hard to tell what exactly is
your question :)

Handling uploaded files and static media can be a little hard at
first. The new (as of 1.3) static media handling is actually very
good, but many net resources still use the old way of handling media
files adding into the confusion. Try to follow the documentation. If
it is hard to follow, please ask again. And remember that improving
documentation is taken seriously in the Django community, so if you
can't follow the documentation, then there is a chance to improve it.

Also, I haven't used nginx, so this is a learning process for me,
too :)

- Anssi

On Jan 29, 1:45 am, Felipe Arruda <felipe.arruda.pon...@gmail.com>
wrote:
> Hi there everyone, I'm trying to make my first deploy of a project,
> and encountered some problems.
> Here is the scenario:
> I read that to make uploaded files only accessible for the
> uploader(the user) was a better choice to use nginx(apparently more
> easy to configure).
> But after following a couple of tutorials(a lot of them actually) I
> still couldn't make it serve the media files, but them I got really
> confuse, and decided that I should review my concepts before trying
> any further.
> So here are my questions:
>
> Does Nginx serve the files that the user upload or just de static
> ones(css, admin_media and stuff)?
> If so:
> -- Could anyone give me an example of configuration for this?
> -- Should I remove the url conf  that maps '^media/(?P<path>.*)$' ?
> If not:
> -- Then how should I config my settings in production so that it
> serves my css and admin_media?
> -- How should Nginx be configured to serve me this?
>
> And also there are other matters, like:
> Should I configure django.sites to point to what? or I don't need this
> set?
> What is better: Copy admin/media to my media folder, or my static
> folder? or should I just make a symlink?
> And finally should I change the directory permissions to the nginx
> user:group? If so, then what directories? Just the media/static, or
> the hole project?(I'm leaving the media/static folder inside the
> project folder, is this a problem to deploy?)
>
> Thanks for the atention, any help is welcome since I've been for 4
> days trying to make this work(in a virtualmachine, testing in lan) and
> still no media/static been served(but I could manage the site to run
> and appear, but no css in admin).

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