0

I have configured my django application on webfaction, and it is working fine as of now. I wanted to know how to serve my static and media files on apache. Django has a development server which serves these files. I had initially setup apache on my local environment and added many lines of script to serve static and media files via apache.

However, while doing the same on webfaction, as per the webfaction docs I didn't have to do much and that got me thinking that there might be more steps needed to serves these files via apache.

Therefore, I wanted to confirm, are my static and media files running from apache or not? I am afraid that this is the case here as well because I have not yet configured apache to serve these files since in development environment django serves the static and media files are served by django itself.

Paolo
  • 20,112
  • 21
  • 72
  • 113
Uma
  • 689
  • 2
  • 12
  • 35
  • 1
    Webfaction uses a separate static-only server to serve your files. – Daniel Roseman Jan 02 '15 at 18:28
  • so you mean I don't have to do anything else as long as I create another static and media application? I will have to run collect static for the same – Uma Jan 02 '15 at 18:30
  • I have actually created 2 static applications on webfaction and assigned them as static and media directories and urls resp. I presume this means these 2 folders will be served by a different server. Is that correct? I ran collectstatic to transfer all the files to static folder. – Uma Jan 02 '15 at 18:33

1 Answers1

3

A typical Django deployment at WebFaction involves at least two application instances:

  • A Django app instance for the version of Django you're running
  • A Symbolic Link to a static-only app instance

The Symbolic link to a static-only app expects you to enter the absolute path for the origin of the symlink. This should point to the directory specified by STATIC_ROOT.

Given an project structure of:

/my-project/
    /my-project/
        settings.py
        ...

    /static_assets/  (used for local development. Not typically deployed.)
    /static/  (used for production)

This would translate to a directory structure at WebFaction like:

/home/
    /your-account-name/
        /webapps/
            /your-django-app-name/
                /apache2
                /bin
                /your-django-app-name  (synonymous with "my-project" above)
                    /static/  (this is what your 'static' symlink path)
                /lib
                    /pythonx.y  (modules go here. Django lives here)

When you create your "Website" instance, you will specify your Django app instance to run on /, and your Symbolic link app instance on the path specified by STATIC_URL, typically /static.

You should run with DEBUG = False at WebFaction, which in turn, causes django.contrib.staticfiles to not serve any files that are located in STATICFILES_DIRS.

Hope that helps you out.

Brandon Taylor
  • 33,823
  • 15
  • 104
  • 144
  • So this means no changes on apache required, and static-only app instance runs on a different server? I am a newbie so just want to make sure :). – Uma Jan 02 '15 at 18:58
  • 1
    Your static app instance and Django instance are on the same server. – Brandon Taylor Jan 02 '15 at 18:59
  • ok, so do I need to change apache conf files to tell it to serve these files? – Uma Jan 02 '15 at 19:01
  • 1
    Your Symbolic Link application instance does that. You just have to provide the path on your website for the app instance to work from, like `/static` for the Symbolic Link, and `/` for the Django app. – Brandon Taylor Jan 02 '15 at 19:02
  • Also, my static dir is outside of your-django-app-name. When I created this folder on webfaction it did this automatically. Just wanted to mention this. – Uma Jan 02 '15 at 19:05
  • 1
    You **do** however, have to change the Apache httpd.conf to point to your wsgi.py file and add any additional directories you want on the pythonpath. – Brandon Taylor Jan 02 '15 at 19:05
  • So you are saying I do not need to do anything else on the apache. Thanks for your help. Much appreciated. – Uma Jan 02 '15 at 19:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/68097/discussion-between-brandon-and-codingmehelp). – Brandon Taylor Jan 02 '15 at 19:06
  • ok, I thought I do not need to include static and media path on apache because I have created it via webfaction static app option. – Uma Jan 02 '15 at 19:07