Nginx as cache: Location extension matching

I want to use a nginx container as proxy-cache. My goal is setting-up an CDN using docker swarm with N replicas of that container.

Well, i have a html page that points at this URL:

 172.17.0.1:9000/media/example-av.mpd

But there is always 404 http response. This is nginx default.conf

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 100m;
proxy_ignore_headers Set-Cookie;

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:8080/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:8080/shaka-player-master/media/example-av.mpd ;

    }




location  ~ /.mpd {

    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:8080/shaka-player-master/media/example-av.mpd ;

    }


}

I've tried extension (.mpd) matching and prefix matching but always 404 not found. I could change URL too, but i need of .mpd extension at the end of URL because of shaka-player (a google library for streaming) constraints.

Can someone help me?

0
задан 2 January 2017 в 13:42
1 ответ

Я решил так: в html-странице я укажу на этот URL:

172.17.0.1:9000/example-av1.mpd

В конфигурационном файле nginx я записал эту строку:

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://172.17.0.1:8080/shaka-player-master/media/example-av1.mpd;
  }
0
ответ дан 5 December 2019 в 08:49

Теги

Похожие вопросы