Home:ALL Converter>django serve media files on both apache and nginx

django serve media files on both apache and nginx

Ask Time:2011-01-28T05:55:33         Author:Neo

Json Formatter

I'm going into production mode for my django project, but running into a peculiar problem. I'm running my django through apahce+mod_wsgi and serving static files through nginx.

However my situation demands that I cannot serve "all" static files from nginx. There is a need to serve only "open-flash-chart.swf" from apache. The project uses openpyc and embeds open-flash-chart.swf which needs to run on same server as django, which in my case is Apache. How can I accomplish that? What changes to I need to make into Apache config files?

server {
listen   80 default;
server_name  localhost;

access_log  /var/log/nginx/localhost.access.log;

location / {
    proxy_pass http://localhost:8080;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k; 
}
location /media/ {
    root /srv/www/enpass/;
    expires max;
}
}

Author:Neo,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/4822359/django-serve-media-files-on-both-apache-and-nginx
Alan Christopher Thomas :

In Apache, set up an alias in your virtual host to serve this file directly:\n\nAlias /url/to/open-flash-chart.swf /full/path/to/open-flash-chart.swf\n\n\nThen, instead of using {{ MEDIA_URL }} to reference the file, code in the absolute path:\n\n<object data=\"/url/to/open-flash-chart.swf\" />\n\n\nNginx will still proxy the request (because it's not your media path), and then Apache will deliver the file back to nginx.\n\nAlternatively, and not recommended, but if it must go straight from Apache to the browser, you could specify the port:\n\n<object data=\"http://servername:8080/url/to/open-flash-chart.swf\" />\n",
2011-01-27T22:53:17
yy