Как использовать мод истекает в Lighttpd

У меня есть сайт, работающий на lighttpd, и я провожу некоторые тесты здесь: https://developers.google.com/speed/pagespeed

Я получаю 89 баллов, но Google говорит:

"Использовать HTTP-заголовки" для некоторых CSS-файлов.

Итак, как мне это сделать, или я могу просто поместить кэши в файл htaccess? И как я их туда вставил, потому что я очень новичок в отношении lighttpd.

Спасибо.

1 ответ

Вы можете следовать на примере, используя настройки сервера lighthttpd H5PB, расположенные по адресу 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" )
Другие вопросы по тегам