在 lighttpd 中访问专用服务器.document-root 返回 404

在 lighttpd 中访问专用服务器.document-root 返回 404

我有一个默认的 lighttpd 安装server.document-root=/var/www/html

/etc/lighttpd/lighttpd.conf

server.modules = (
    "mod_indexfile",
    "mod_access",
    "mod_alias",
    "mod_redirect",
)

server.document-root        = "/var/www/html"
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"
server.port                 = 80

# strict parsing and normalization of URL for consistency and security
# https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_http-parseoptsDetails
# (might need to explicitly set "url-path-2f-decode" = "disable"
#  if a specific application is encoding URLs inside url-path)
server.http-parseopts = (
  "header-strict"           => "enable",# default
  "host-strict"             => "enable",# default
  "host-normalize"          => "enable",# default
  "url-normalize-unreserved"=> "enable",# recommended highly
  "url-normalize-required"  => "enable",# recommended
  "url-ctrls-reject"        => "enable",# recommended
  "url-path-2f-decode"      => "enable",# recommended highly (unless breaks app)
 #"url-path-2f-reject"      => "enable",
  "url-path-dotseg-remove"  => "enable",# recommended highly (unless breaks app)
 #"url-path-dotseg-reject"  => "enable",
 #"url-query-20-plus"       => "enable",# consistency in query string
)

index-file.names            = ( "index.php", "index.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

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

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.conf.pl"
include "/etc/lighttpd/conf-enabled/*.conf"

#server.compat-module-load   = "disable"
server.modules += (
    "mod_compress",
    "mod_dirlisting",
    "mod_staticfile",
)

然后我还有一些其他网页,当我使用或使用时/var/www/rss应该提供服务。所以我引入了这个配置https://myip/rsshttps://rss.mydomain.dev

/etc/lighttpd/conf-enabled/20-tt-rss.conf

$HTTP["url"] =~ "^/rss/" {
    server.document-root = "/var/www/rss"
    dir-listing.activate = "disable"
    $HTTP["url"] =~ "^/rss/(locale|classes|schema|lock|utils|cache|templates|\.git)/" {
        url.access-deny = ( "" )
    }
    expire.url = (
        "/rss/css/" => "access plus 1 days",
        "/rss/images/" => "access plus 1 days",
        "/rss/js/" => "access plus 1 days",
        "/rss/feed-icons/" => "access plus 1 hours"
    )
} else $HTTP["host"] == "rss.mydomain.dev" {
    server.document-root = "/var/www/rss"
    dir-listing.activate = "disable"
    $HTTP["url"] =~ "rss.mydomain.com/(locale|classes|schema|lock|utils|cache|templates|\.git)/" {
        url.access-deny = ( "" )
    }
    expire.url = (
        "rss.mydomain.dev/css/" => "access plus 1 days",
        "rss.mydomain.dev/images/" => "access plus 1 days",
        "rss.mydomain.dev/js/" => "access plus 1 days",
        "rss.mydomain.dev/feed-icons/" => "access plus 1 hours"
    )   
}

使用时http://myip/rss/我得到 404

404 错误

使用时http://rss.mydomain.dev我得到“占位符页面”

占位页

我显然遗漏了一些东西,但作为 lighttpd 的新用户,我不知道是什么。

答案1

lighttpd 调试变量提供有关 lighttpd 如何处理请求的详细信息,可能对您有用。

另一个选择是使用strace -s 1024lighttpd 进程,发出请求,并检查文件系统访问。

lighttpd 配置处理按程序进行,按照配置的顺序进行。如果您有多个设置条件server.document-root,则最后一个与请求匹配并设置的条件server.document-root将对生效server.document.root。(全局设置被视为首先设置,无论它们出现在配置中的什么位置)

虽然您lighttpd.conf在问题中包含了您的信息,但您没有包含完整的配置。请尝试运行lighttpd -f /etc/lighttpd/lighttpd.conf -p以打印完整的配置。

另外:不正确的使用: $HTTP["url"] =~ "rss.mydomain.com/(locale|classes|schema|lock|utils|cache|templates|\.git)/"$HTTP["url"]经过 URL 解码和规范化的 URL 路径。URL 路径不包含权限(“rss.mydomain.com”) 同样,您expire.url对“rss.mydomain.dev”的使用也是不正确的。

相关内容