【问题标题】:How to use mod expire in lighttpd如何在 lighttpd 中使用 mod expire
【发布时间】:2014-11-05 21:46:31
【问题描述】:

我的网站在 lighttpd 上运行,我在这里运行了一些测试:https://developers.google.com/speed/pagespeed

我得到 89 分,但谷歌说:

对一些 css 文件“使用 HTTP-Headers”。

那么我该怎么做,或者我可以将缓存放在 htaccess 文件中吗?以及我如何将这些放在那里,因为我对 lighttpd 非常陌生。

谢谢。

【问题讨论】:

    标签: lighttpd mod-expires


    【解决方案1】:

    您可以使用位于以下位置的H5PB's lighthttpd 服务器配置进行示例操作 https://github.com/h5bp/server-configs-lighttpd/blob/master/lighttpd.conf

    例子:

    # Modules to load
    # at least mod_access and mod_accesslog should be loaded
    # mod_expire should go above mod_compress (and mod_fcgi if you use it)
    # otherwise expire headers will not be applied to compressed documents.
    server.modules = (
        "mod_access",
        "mod_accesslog",
        "mod_redirect",
        "mod_expire",
        "mod_compress",
        "mod_setenv"
    )
    
    
    # Compression
    # Make sure this folder exists and is writable to server.username
    compress.cache-dir = "/tmp/lighttpd/compress/"
    compress.filetype = (
        "application/atom+xml",
        "application/javascript",
        "application/json",
        "application/rss+xml",
        "application/vnd.ms-fontobject",
        "application/x-font-ttf",
        "application/x-web-app-manifest+json",
        "application/xhtml+xml",
        "application/xml",
        "font/opentype",
        "image/svg+xml",
        "image/x-icon",
        "text/css",
        "text/html",
        "text/plain",
        "text/x-component",
        "text/xml",
    )
    
    # Proper MIME types for all files
    mimetype.assign = (
    
        ".appcache"     =>      "text/cache-manifest" ,
        ".crx"          =>      "application/x-chrome-extension",
        ".css"          =>      "text/css",
        ".eot"          =>      "application/vnd.ms-fontobject",
        ".htc"          =>      "text/x-component",
        ".htm"          =>      "text/html",
        ".html"         =>      "text/html",
        ".ico"          =>      "image/x-icon",
        ".js"           =>      "application/javascript",
        ".json"         =>      "application/json",
        ".manifest"     =>      "text/cache-manifest" ,
        ".oex"          =>      "application/x-opera-extension",
        ".otf"          =>      "font/opentype",
        ".safariextz"   =>      "application/octet-stream",
        ".swf"          =>      "application/x-shockwave-flash",
        ".ttc"          =>      "application/x-font-ttf",
        ".ttf"          =>      "application/x-font-ttf",
        ".vcf"          =>      "text/x-vcard",
        ".vtt"          =>      "text/vtt",
        ".webapp"       =>      "application/x-web-app-manifest+json",
        ".webp"         =>      "image/webp",
        ".woff"         =>      "application/font-woff",
        ".xpi"          =>      "application/x-xpinstall",
    
        ".pdf"          =>      "application/pdf",
        ".sig"          =>      "application/pgp-signature",
        ".spl"          =>      "application/futuresplash",
        ".class"        =>      "application/octet-stream",
        ".ps"           =>      "application/postscript",
        ".torrent"      =>      "application/x-bittorrent",
        ".dvi"          =>      "application/x-dvi",
        ".gz"           =>      "application/x-gzip",
        ".pac"          =>      "application/x-ns-proxy-autoconfig",
        ".tar.gz"       =>      "application/x-tgz",
        ".tgz"          =>      "application/x-tgz",
        ".tar"          =>      "application/x-tar",
        ".zip"          =>      "application/zip",
        ".mp3"          =>      "audio/mpeg",
        ".m3u"          =>      "audio/x-mpegurl",
        ".wma"          =>      "audio/x-ms-wma",
        ".wax"          =>      "audio/x-ms-wax",
        ".ogg"          =>      "application/ogg",
        ".oga"          =>      "audio/ogg",
        ".ogv"          =>      "video/ogg",
        ".wav"          =>      "audio/x-wav",
        ".gif"          =>      "image/gif",
        ".jar"          =>      "application/x-java-archive",
        ".jpg"          =>      "image/jpeg",
        ".jpeg"         =>      "image/jpeg",
        ".png"          =>      "image/png",
        ".xbm"          =>      "image/x-xbitmap",
        ".xpm"          =>      "image/x-xpixmap",
        ".xwd"          =>      "image/x-xwindowdump",
        ".asc"          =>      "text/plain",
        ".c"            =>      "text/plain",
        ".cpp"          =>      "text/plain",
        ".log"          =>      "text/plain",
        ".conf"         =>      "text/plain",
        ".text"         =>      "text/plain",
        ".txt"          =>      "text/plain",
        ".dtd"          =>      "text/xml",
        ".xml"          =>      "text/xml",
        ".mpeg"         =>      "video/mpeg",
        ".mpg"          =>      "video/mpeg",
        ".mov"          =>      "video/quicktime",
        ".qt"           =>      "video/quicktime",
        ".avi"          =>      "video/x-msvideo",
        ".asf"          =>      "video/x-ms-asf",
        ".asx"          =>      "video/x-ms-asf",
        ".wmv"          =>      "video/x-ms-wmv",
        ".bz2"          =>      "application/x-bzip",
        ".tbz"          =>      "application/x-bzip-compressed-tar",
        ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
    
        # default MIME type
        ""              =>      "application/octet-stream",
    )
    
    
    
    # Extensions that should not be handle via static-file transfer.
    # .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
    static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
    
    
    # Expires headers (for better cache control)
    # The following expires headers are set pretty far in the future. If you don't
    # control versioning with filename-based cache busting, consider lowering the
    # cache time for resources like CSS and JS to something like 1 week.
    
    # CSS
    $HTTP["url"] =~ ".css" {
        expire.url = ( "" => "access plus 1 years" )
    }
    
    # Data interchange
    $HTTP["url"] =~ ".(json|xml)" {
        expire.url = ( "" => "access plus 0 seconds" )
    }
    
    # Favicon
    $HTTP["url"] =~ ".ico" {
        expire.url = ( "" => "access plus 7 days" )
    }
    
    # HTML components (HTCs)
    $HTTP["url"] =~ ".htc" {
        expire.url = ( "" => "access plus 1 months" )
    }
    
    # HTML
    $HTTP["url"] =~ ".html" {
        expire.url = ( "" => "access plus 0 seconds" )
    }
    
    # JavaScript
    $HTTP["url"] =~ ".js" {
        expire.url = ( "" => "access plus 1 years" )
    }
    
    # Manifest files
    $HTTP["url"] =~ ".(appcache|manifest|webapp)" {
        expire.url = ( "" => "access plus 0 seconds" )
    }
    
    # Media
    $HTTP["url"] =~ ".(gif|jpg|jpeg|png|m4a|f4a|f4b|oga|ogg|webm)" {
        expire.url = ( "" => "access plus 1 months" )
    }
    
    # Web feeds
    $HTTP["url"] =~ ".(atom|rss)" {
        expire.url = ( "" => "access plus 1 hours" )
    }
    
    # Web fonts
    $HTTP["url"] =~ ".(eot|otf|svg|svgz|ttf|ttc|woff)" {
        expire.url = ( "" => "access plus 1 months" )
    }
    
    # Default
    expire.url = ( "" => "access plus 1 months" )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-04
      • 2015-06-22
      • 1970-01-01
      • 2023-02-12
      • 2018-06-29
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多