Saturday, August 27, 2011

cake and lighttpd on csotelo.org

Hi 

I can not solve css/img/js/files on my vps, I think is a poble with the module rewrite for the assets, but I am really new on lighttpd and I just uncoment the line eich refers to the rewrite module

it is using lighttpd with magnet
server.modules = (
        "mod_access",
        "mod_alias",
        "mod_compress",
        "mod_redirect",
        "mod_rewrite",
)

server.document-root        = "/var/www/"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"

index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm",
                               " index.lighttpd.html" )

url.access-deny             = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

include_shell "/usr/share/lighttpd/use-ipv6.pl"

dir-listing.encoding        = "utf-8"
server.dir-listing          = "enable"

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"


$HTTP["host"] =~ "csotelo.org" {
        server.error-handler-404  = "/index.php"
        server.document-root = "/home/csotelo/public_html"

        #url.rewrite = (
        #       "(css|files|img|js)/(.*)" => "/$1/$2"
        #)
        url.rewrite-once = (
                "/(css|files|img|js)/(.*)" => "/$1/$2",
                #"^([^\?]*)(\?(.+))?$" => "/index.php?url=$1&$3",
        )
        magnet.attract-physical-path-to = ( "/etc/lighttpd/cake.lua" )
}

the lua file is

-- pequeña funcion helper
function file_exists(path)
  local attr = lighty.stat(path)
  if (attr) then
      return true
  else
      return false
  end
end
function removePrefix(str, prefix)
  return str:sub(1,#prefix+1) == prefix.."/" and str:sub(#prefix+2)
end

-- prefijo sin la barra
local prefix = ''

-- la magia ;)
if (not file_exists(lighty.env["physical.path"])) then
    -- fichero aún desaparecido, pasarlo al fastcgi Backend
    request_uri = removePrefix(lighty.env["uri.path"], prefix)
    if request_uri then
      lighty.env["uri.path"]          = prefix .. "/index.php"
      local uriquery = lighty.env["uri.query"] or ""
      lighty.env["uri.query"] = uriquery .. (uriquery ~= "" and "&" or "") .. "url=" .. request_uri
      lighty.env["physical.rel-path"] = lighty.env["uri.path"]
      lighty.env["request.orig-uri"]  = lighty.env["request.uri"]
      lighty.env["physical.path"]     = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
    end
end
-- fallthrough pondrá de nuevo la solucititud en el bucle lighty
-- eso significa que tenemos la manipulación 304 de forma gratuita. ;)


Eaiting your help
--
Carlos Eduardo Sotelo Pinto
    GNU Linux Admin | PHP Senior Web Developer
    MObil: RPC (Claro)+51, 958194614
    Skype: csotelop
    Yahoo: csotelop
GPG FP:697E FAB8 8E83 1D60 BBFB 2264 9E3D 5761 F855 4F6B
GNULinux RU #379182 || GNULinux RM #277661

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: