Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django NGINX:从不同位置提供静态文件_Django_Apache_File_Nginx_Static - Fatal编程技术网

Django NGINX:从不同位置提供静态文件

Django NGINX:从不同位置提供静态文件,django,apache,file,nginx,static,Django,Apache,File,Nginx,Static,我在两台不同的机器上实现了两台服务器(不同的IP地址)。让我们把它们称为serverA和serverB serverA是serverB为一些静态文件提供数据的地方 服务器A配置文件是: limit_req_zone $binary_remote_addr zone=lmz_serverA:10m rate=5r/s; server { listen 80; ## listen for ipv4; this line is default and implied serve

我在两台不同的机器上实现了两台服务器(不同的IP地址)。让我们把它们称为serverAserverB

serverAserverB为一些静态文件提供数据的地方

服务器A配置文件是:

limit_req_zone $binary_remote_addr zone=lmz_serverA:10m rate=5r/s;

server {
    listen   80; ## listen for ipv4; this line is default and implied

    server_name serverA;

    location /server_a {
    limit_req zone=lmz_serverA burst=5 nodelay;
    rewrite /server_a/(.*) /$1 break;
    proxy_intercept_errors     on;
    proxy_pass http://0.0.0.0: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;
    }


    location /static/BIG/ {
    root /safe/server_a/;
    autoindex off;
    expires 7d;
    }

    location /server_a/static/{
    root /safe/;
    autoindex off;
    expires 7d;
    }

    location = /favicon.ico{
    alias /safe/server_a/static/images/favicon.ico;
    }
}
limit_req_zone $binary_remote_addr zone=lmz_serverB:10m rate=5r/s;

server {
    listen   80; ## listen for ipv4; this line is default and implied

    server_name serverB;

    location /server_b {
    limit_req zone=lmz_serverB burst=5 nodelay;
    rewrite /server_b/(.*) /$1 break;
    proxy_intercept_errors     on;
    proxy_pass http://1.0.0.0: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;
    }

    location /server_b/static/ {
    root /safe/;
    autoindex off;
    expires 7d;
    }
服务器B配置文件是:

limit_req_zone $binary_remote_addr zone=lmz_serverA:10m rate=5r/s;

server {
    listen   80; ## listen for ipv4; this line is default and implied

    server_name serverA;

    location /server_a {
    limit_req zone=lmz_serverA burst=5 nodelay;
    rewrite /server_a/(.*) /$1 break;
    proxy_intercept_errors     on;
    proxy_pass http://0.0.0.0: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;
    }


    location /static/BIG/ {
    root /safe/server_a/;
    autoindex off;
    expires 7d;
    }

    location /server_a/static/{
    root /safe/;
    autoindex off;
    expires 7d;
    }

    location = /favicon.ico{
    alias /safe/server_a/static/images/favicon.ico;
    }
}
limit_req_zone $binary_remote_addr zone=lmz_serverB:10m rate=5r/s;

server {
    listen   80; ## listen for ipv4; this line is default and implied

    server_name serverB;

    location /server_b {
    limit_req zone=lmz_serverB burst=5 nodelay;
    rewrite /server_b/(.*) /$1 break;
    proxy_intercept_errors     on;
    proxy_pass http://1.0.0.0: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;
    }

    location /server_b/static/ {
    root /safe/;
    autoindex off;
    expires 7d;
    }
---结束

现在,想象一下这些服务器位于不同的大陆。。一些静态文件可以从服务器A获得服务,但是大型(/static/BIG/)文件给我带来了一些麻烦,因为大多数用户都在服务器B的同一个大陆上。因此,我想从serverA中剪切这些大的静态文件,并将它们放在serverB上,以便更容易地下载它们

有人知道我如何通过在serverB上提供这些文件并更改nginx配置文件来实现这一点吗

重要serverA实现名为appA的Django应用程序,serverB实现名为appB的不同(但仍然是Django)应用程序。我无法更改这两个应用程序的代码


提前谢谢

您可以从希望另一个服务器为大文件服务的服务器执行临时移动的
302
重定向

server_name serverA;
location /static/BIG/ {
    return  302 $scheme://serverB$uri;
}

我在搜索类似的东西时偶然发现了这个问题--如何提供不同于请求的文件名。我的最终解决方案:

location /robots.txt {
       # Try the beta file, which has a disallow everything
       root /location/to/static/files;
       try_files /robots-beta.txt =404;
}

谢谢,我会试试的!serverB是否直接将文件提供给请求者,或者文件将从serverB传输到serverA,然后再提供(使serverA成为代理)?我希望这些文件直接送达,因为在另一种情况下,我不会得到任何东西。它们将直接送达。但是请注意,仍然会向serverA发出请求(伴随着一个非常小的重定向响应),因此,延迟会受到影响——如果这不是您想要的,那么您应该在serverB上将html更改为reference/static/BIG/directly。。在“返回302”行$scheme://serverB$uri;”如果serverB有ip:1.1.1.1和文件夹,并且位置相同/静态/大,您将如何重写该行?返回302美元方案:???好的,就像你说的那样。。返回302scheme://1.1.1.1$uri;除了一些闪光的东西,所有的静电都会被提供。。I get:crossdomain.xml get 404未找到