2017-01-19 12 views
0

ロードバランサとして機能するポート9200のnginxコンテナがあります。これは設定ファイルです:ロードバランサとしてのnginx:上流のパス

proxy_ignore_headers Set-Cookie; 
add_header 'Access-Control-Allow-Origin' '*'; 
add_header 'Access-Control-Allow-Headers' 'Range'; 


upstream backend { 
     server 192.168.99.103:9500 weight=3; 
     server 192.168.99.104:9500; 
     server 192.168.99.105:9500; 
    } 

server { 

listen 80; 
server_name 172.17.0.1; 

location = /LynyrdSkynyrdFreebirdAudio.mp4 { 

      add_header 'Access-Control-Allow-Origin' '*'; 
      add_header 'Access-Control-Allow-Headers' 'Range'; 

      if ($request_method = OPTIONS) { 
       add_header Access-Control-Allow-Methods "GET, OPTIONS"; 
       add_header Content-Length 0; 
       add_header Content-Type text/plain; 
       return 200; 
       } 
      proxy_pass http://backend/; 

      add_header X-Upstream $upstream_addr; 

     } 

     location = /LynyrdSkynyrdFreebirdVideo.mp4 { 
      add_header 'Access-Control-Allow-Origin' '*'; 
      add_header 'Access-Control-Allow-Headers' 'Range'; 

      if ($request_method = OPTIONS) { 
       add_header Access-Control-Allow-Methods "GET, OPTIONS"; 
       add_header Content-Length 0; 
       add_header Content-Type text/plain; 
       return 200; 
       } 

      proxy_pass http://backend; 

      add_header X-Upstream $upstream_addr; 
     } 

    } 

次のようにこのコンテナの負荷バランスの要求:要求localhost:9200/LynyrdSkynyrdFreebirdVideo.mp4またはlocalhost:9200/LynyrdSkynyrdFreebirdAudio.mp4を到着したとき、それは3台のサーバ間での要求のバランスをとります。 これらの3つのサーバーは、キャッシュとして機能する3つのnginxコンテナーです。 これはnginxのキャッシュの設定ファイルである:私は、ロードバランサ、すなわちlocalhost:9200/LynyrdSkynyrdFreebirdVideo.mp4またはlocalhost:9200/LynyrdSkynyrdFreebirdAudio.mp4を指す場合

proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:10m inactive=60m; 
proxy_cache_key "$scheme$request_method$host$request_uri"; 
proxy_cache_methods GET HEAD POST; 
proxy_cache_valid 200 206 100m; 
proxy_ignore_headers Set-Cookie; 
add_header 'Access-Control-Allow-Origin' '*' always; 
add_header 'Access-Control-Allow-Headers' 'Range'; 
server { 
    listen  80; 
    server_name 172.17.0.1; 

    #charset koi8-r; 
    #access_log /var/log/nginx/log/host.access.log main; 

    location/{ 
    } 

    #error_page 404    /404.html; 

    # redirect server error pages to the static page /50x.html 
    # 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /usr/share/nginx/html; 
    } 

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
    # 
    #location ~ \.php$ { 
    # proxy_pass http://127.0.0.1; 
    #} 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    #location ~ \.php$ { 
    # root   html; 
    # fastcgi_pass 127.0.0.1:9000; 
    # fastcgi_index index.php; 
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
    # include  fastcgi_params; 
    #} 

    # deny access to .htaccess files, if Apache's document root 
    # concurs with nginx's one 
    # 
    #location ~ /\.ht { 
    # deny all; 
    #} 

    location /demo/ { 

    proxy_cache my_zone; 
    add_header X-Proxy-Cache    $upstream_cache_status; 
    proxy_set_header X-Real-IP   $remote_addr; 
    proxy_set_header X-Forwarded-For  $remote_addr; 

    proxy_set_header Host    $host; 

    proxy_pass http://172.17.0.1:8700/shaka-player-master/demo/index1.html ; 

    } 

location /media { 

    proxy_cache my_zone; 
    add_header X-Proxy-Cache    $upstream_cache_status; 
    proxy_set_header X-Real-IP   $remote_addr; 
    proxy_set_header X-Forwarded-For  $remote_addr; 

    proxy_set_header Host    $host; 

    proxy_pass http://172.17.0.1:8700/shaka-player-master/media/example-av.mpd ; 

    } 

location = /example-av1.mpd { 
    add_header 'Access-Control-Allow-Origin' '*'; 

    proxy_cache my_zone; 
    add_header X-Proxy-Cache    $upstream_cache_status; 
    proxy_set_header X-Real-IP   $remote_addr; 
    proxy_set_header X-Forwarded-For  $remote_addr; 

    proxy_set_header Host    $host; 

    proxy_pass http://192.168.99.103:9600/shaka-player/media/example-av1.mpd; 
    } 



location = /LynyrdSkynyrdFreebirdVideo.mp4 { 
    add_header 'Access-Control-Allow-Origin' '*'; 
    add_header 'Access-Control-Allow-Headers' 'Range'; 


    proxy_cache my_zone; 
    add_header X-Proxy-Cache    $upstream_cache_status; 
    proxy_set_header X-Real-IP   $remote_addr; 
    proxy_set_header X-Forwarded-For  $remote_addr; 

    proxy_set_header Host    $host; 

    proxy_pass http://192.168.99.103:9600/shaka-player/media/LynyrdSkynyrdFreebirdVideo.mp4 ; 

    } 

location = /LynyrdSkynyrdFreebirdAudio.mp4 { 
    add_header 'Access-Control-Allow-Origin' '*'; 
    add_header 'Access-Control-Allow-Headers' 'Range'; 


    proxy_cache my_zone; 
    add_header X-Proxy-Cache    $upstream_cache_status; 
    proxy_set_header X-Real-IP   $remote_addr; 
    proxy_set_header X-Forwarded-For  $remote_addr; 

    proxy_set_header Host    $host; 

    proxy_pass http://192.168.99.103:9600/shaka-player/media/LynyrdSkynyrdFreebirdAudio.mp4; 

    } 

} 

、見つからない404があります。私は、このURLを指していれば、ロードバランサは192.168.99.103(or 104, or 105):9500/LynyrdSkynyrdFreebirdVideo.mp 4または192.168.99.103(or 104, or 105):9500/LynyrdSkynyrdFreebirdAudio.mp4にリクエストのバランスをとることを期待しています。 しかし、upstreamブロックでは、serverディレクティブにパスを追加できるかどうかわかりません。実際に

、これは、私が思うに、非常に問題である:私は192.168.99.103 を指している場合、実際には、:9500/LynyrdSkynyrdFreebirdAudio(またはビデオ).MP4、私は正しくコンテンツを取得します。

誰でも助けてくれますか?

答えて

0

は解決:

proxy_pass http://backend/LynyrdSkynyrdFreebirdVideo.mp4; 

を私は好き、http://backendへのパスを追加しました

関連する問題