今天在測試業務的時候,發現微信小程序有點問題, 而後本身起了一個nginx 模擬hls拉流的過程。 而後發現 index.m3u8文件老是沒法獲取下來。 首先肯定了一下是 content-type的問題。 由於在同一個location內部有兩種不一樣的 mime類型 後綴爲.m3u8的類型是 application/vnd.apple.mpegurl 類型, 而後ts文件的類型是 application/octet-stream 類型。 用openresty更改完成以後, 發現依然會掛起。 想起來在nginx的不一樣生命週期 階段處理這個內容纔是。要否則被覆蓋了,沒有改更改。 索性就放在了header過濾階段。html
配置以下。nginx
┊ ┊location / {
103 ┊ ┊ ┊header_filter_by_lua_block { 104 ┊ ┊ ┊ ┊local eax = ngx.header; 105
106 ┊ ┊ ┊ ┊if eax.request_filename ~= nil and string.find(eax.request_filename, ".ts") ~= nil then 107 ┊ ┊ ┊ ┊ eax.content_type = "application/octet-stream" ; 108 ┊ ┊ ┊ ┊else
109 ┊ ┊ ┊ ┊ eax.content_type = "application/vnd.apple.mpegurl"; 110 ┊ ┊ ┊ ┊end
111 ┊ ┊ ┊}
112 ┊ ┊ ┊root html;
113 ┊ ┊ ┊index index.html;
114 }web
最近不多玩http的服務,搞websoket推流的服務多一些,不過思惟仍是有的 ,解決問題用時10分59秒。小程序