0
votes

I have a number of PHP sites running on Apache, however I am about to launch my first Django site. I have successfully got WSGI working on Apache to handle the Python scripts but I am a bit stuck with using Nginx to serve my media files.

I know I need to make Apache listen on a different port and get Nginx to listen on port 80, then forward any non-media requests to Apache on port 8080.

What I really want to know is, is there an easy way to configure it to work with all of my existing sites or do I need to set up a separate record for every one of my current sites just to forward the requests to port 8080?

Any advice appreciated.

Thanks

1
Do you actually need to use Nginx? Apache can serve the media files too.Daniel Roseman
I don't need to, but I am trying to follow the recommended guidelines in the documentationDan
Are you looking to use nginx as a reverse proxy for apache or just as a media server?j_syk
I just want to use it to serve static files in my Django applicationsDan

1 Answers

1
votes

If you scroll down a bit in the Django documentation about serving static files, they give you the information on how to make Apache serve the files for you so that you don't need nginx (assumes your media files are in /usr/local/wsgi/static/media/):

Alias /robots.txt /usr/local/wsgi/static/robots.txt
Alias /favicon.ico /usr/local/wsgi/static/favicon.ico

AliasMatch ^/([^/]*\.css) /usr/local/wsgi/static/styles/$1

Alias /media/ /usr/local/wsgi/static/media/

<Directory /usr/local/wsgi/static>
    Order deny,allow
    Allow from all
</Directory>

WSGIScriptAlias / /usr/local/wsgi/scripts/django.wsgi

<Directory /usr/local/wsgi/scripts>
    Order allow,deny
    Allow from all
</Directory>

If, however, you are dead set on using nginx, you would add your static directives in your server {} directive:

location /media/ {
    access_log off; # who cares about static files?
    alias /usr/local/wsgi/static/media/;
    expires 30d; # enables caching.
}