flv streaming and proxy_pass

Karolis karolis at pg.lt
Tue Feb 24 23:20:34 MSK 2009


> @Karolis: how exactly can you do this with lighttpd? Any reference?
>
> Michal
>   
Just to make it clear: it works now on nginx too, using code from  Cliff 
Wells;

Regarding lighty, you can do the same (similar) with mod_magnet. The 
difference
is that with lighty I used to pass the request to php-fcgi instead of 
apache. But I actually
like using apache better, as our cache miss rate is very low and I find 
it much easier
to maintain apache/mod_php installation than php-fcgi.

anyway, in lighttpd.conf:
  magnet.attract-physical-path-to = (server.document-root + "/content.lua")

Then content.lua would be similar to this:

--------------------------------------------------------------------
-- Get full request URL
full_request = lighty.env["uri.path"]

-- Check if the URL has required syntax
id_request = string.match(full_request, "^/dbfile/%d+/")

-- Create 9-char zero-padded file ID
file_id = string.match(id_request, "%d+")
pad_id = string.format("%09d", file_id)

part1 = string.sub(pad_id, 1, 3)
part2 = string.sub(pad_id, 4, 6)
part3 = string.sub(pad_id, 7, 9)


file_path = "cache/" .. part1 .. "/" .. part2 .. "/" .. file_id .. "__" 
.. filename
stat = lighty.stat(lighty.env["physical.doc-root"] .. file_path)

if stat and stat["is_file"] then
  -- Rewrite to show image/movie
  lighty.env["uri.path"] = file_path
  lighty.env["physical.rel-path"] = lighty.env["uri.path"]
  lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. 
lighty.env["physical.rel-path"]

  lighty.status["cache.hit"] = lighty.status["cache.hit"] + 1
else
  -- Rewrite to generator script
  lighty.env["uri.path"] = "/file.php"
  lighty.env["uri.query"] = "id=" .. pad_id
  lighty.env["physical.rel-path"] = lighty.env["uri.path"]
  lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. 
lighty.env["physical.rel-path"]

  lighty.status["cache.miss"] = lighty.status["cache.miss"] + 1
end
--------------------------------------------------------------------

This is probably by far not the most efficient way to do it, but this 
was my first lua script and it worked, so...

PS. I miss cache.hit and cache.miss features a lot . Does nginx have any 
similar counters?

Karolis






More information about the nginx mailing list