S
S
Salavat Sharapov2014-03-13 07:43:31
Django
Salavat Sharapov, 2014-03-13 07:43:31

How to send MEDIA_ROOT to another host?

Good afternoon.
Python 2.7+Django 1.4. 4 servers work: 1 front (debian7,nginx) and upstream for 3 backends (debian 7, apache), all have the same repository. The static is collected on the frontend and it gives it away. There is media for the test only on one of the backends. But we need to make sure that all media is on the frontend.
How can I make Apache pick up and put media from/to the frontend?
How can I connect the frontend server (namely the media folder) in the settings.py of the backend?http? ssh? nfs?
Or is it possible to somehow implement this through nginx itself? Maybe through rewrites?
Thank you for your feedback and answers , p.s. nginx config:
front.test:

upstream backend {
    ip_hash;
    server 192.168.0.231:8080;
    server 192.168.0.232:8080 down;
    server 192.168.0.233:8080 down;
}

server {
    listen    80;
    server_name  web.ru;

 location ~ /\.ht {
        deny all;
}

# location ~*\.(bmp|class|css|doc|flv|gif|ico|jpg|jpeg|js|mov|mp3|pdf|png|ppt|rtf|swf|txt|xls|xml|eot|otf|svg|ttf|$
#        root /home/user/app/;
#}

 location ~ ^/(media|static) {
        root /home/user/app/;
 }

 location  / {
        client_max_body_size    101m;
        client_body_buffer_size 128k;
        proxy_send_timeout   90;
        proxy_read_timeout   90;
        proxy_buffer_size    4k;
        proxy_buffers     16 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
        proxy_connect_timeout 30s;
        proxy_pass   http://backend;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
}

 location = /50x.html {
        root   /usr/share/nginx/html;
}

 error_page  404              /404.html;

 error_page   500 502 503 504  /50x.html;

}

part of settings.py on backend
....
MEDIA_URL = '/media/'
MEDIA_ROOT = '/home/userbackend/app'
....

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vit, 2014-03-13
@desperadik

We really don’t have a python, but php, but we used nfs for similar purposes.

U
un1t, 2014-03-13
@un1t

We had something similar on one project. There was one backend with an admin panel and many fronts. We wrote a dectorator that, using rsync, transferred the necessary files to all servers. This decorator was set to save in the admin panel.
Alternatively, on location / media, you can hang proxy_pass on the backend, but I don’t know how appropriate this is in your case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question