server.conf 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # webserver config https://lighttpd.net
  2. var.baseurl = "/"
  3. auth.backend = "htdigest"
  4. auth.backend.htdigest.userfile = "/etc/lighttpd/internet-radio-recorder.user.htdigest"
  5. # $ sudo htdigest -c /etc/lighttpd/internet-radio-recorder.user.htdigest 'Radio Pi' <uid>
  6. $HTTP["request-method"] == "HEAD" {
  7. # allowed
  8. } else $HTTP["query-string"] == "atom" {
  9. # allowed
  10. } else $HTTP["query-string"] == "rss" {
  11. # allowed
  12. } else $HTTP["url"] =~ "\.mp3$" {
  13. # for legal reasons mp3 access must be restricted, http://de.wikipedia.org/wiki/Privatkopie#Deutschland
  14. auth.require = ( baseurl + "enclosures" => (
  15. # see /usr/share/doc/lighttpd/authentication.txt.gz
  16. "method" => "digest",
  17. "realm" => "Radio Pi",
  18. "require" => "valid-user",
  19. ), )
  20. }
  21. # http://www.golem.de/news/content-security-policy-schutz-vor-cross-site-scripting-1306-99795.html
  22. setenv.add-response-header = (
  23. # http://www.w3.org/TR/CSP/#example-policies
  24. # 'unsafe-inline' for the lighttpd-generated directory listings
  25. "Content-Security-Policy" => "default-src 'none'; style-src 'self' 'unsafe-inline'; script-src 'self'; connect-src 'self'; font-src 'self'; img-src *;",
  26. )
  27. # enable directory browsing:
  28. dir-listing.activate = "enable"
  29. dir-listing.encoding = "utf-8"
  30. dir-listing.show-readme = "enable"
  31. url.redirect = (
  32. "^" + baseurl + "(stations/[^/]+)/now(\?.*)?$" => "../../app/onair.cgi/$1$2",
  33. "^" + baseurl + "podcasts/[^/]+/([^/]+/[0-9]{4}/[0-9]{2}/[0-9]{2}/[0-9]{4})$" => "../../../../../../stations/$1.xml",
  34. "^" + baseurl + "podcasts/([^/]+)\.(atom|rss)$" => "$1/broadcasts.$2",
  35. # legacy <2022:
  36. "^" + baseurl + "(podcasts/radio)_(mitschnitt/broadcasts.rss)$" => "../../$1$2",
  37. "^" + baseurl + "stations/[^/]+/[0-9]{4}/[0-9]{2}/[0-9]{2}/([0-9]{4})( .+)?$" => "$1.xml",
  38. )
  39. $HTTP["url"] =~ "\.xml\.gz$" {
  40. # serve pre-compressed content to be unpacked by client
  41. setenv.add-response-header = ( "Content-Encoding" => "gzip")
  42. mimetype.assign = (".xml.gz" => "text/xml; charset=utf-8" )
  43. }
  44. cgi.assign = (
  45. "app/monitor.cgi" => "/bin/dash",
  46. "app/onair.cgi" => "/bin/dash",
  47. "enclosures/app/ad_hoc.cgi" => "/bin/dash",
  48. "i.cgi" => "/bin/dash",
  49. )
  50. # proper mimetypes + encodings:
  51. mimetype.assign = (
  52. ".atom" => "text/xml; charset=utf-8",
  53. ".aac" => "audio/aac",
  54. ".cfg" => "text/plain; charset=utf-8",
  55. ".css" => "text/css; charset=utf-8",
  56. ".html" => "text/html; charset=utf-8",
  57. ".ico" => "image/vnd.microsoft.icon",
  58. ".ics" => "text/calendar; charset=utf-8",
  59. ".json" => "application/json; charset=utf-8",
  60. ".js" => "text/javascript; charset=utf-8",
  61. ".log" => "text/plain; charset=utf-8",
  62. ".m4a" => "audio/mpeg",
  63. ".mp3" => "audio/mpeg",
  64. ".pending" => "text/plain; charset=utf-8",
  65. ".png" => "image/png",
  66. ".podcasts" => "text/plain; charset=utf-8",
  67. ".rdf" => "application/rdf+xml; charset=utf-8",
  68. ".reserved" => "text/plain; charset=utf-8",
  69. ".ripping" => "audio/mpeg",
  70. ".rnc" => "text/plain; charset=utf-8",
  71. ".rng" => "text/xml; charset=utf-8",
  72. ".rss" => "application/rss+xml; charset=utf-8",
  73. ".scheduled" => "text/plain; charset=utf-8",
  74. ".sh" => "text/plain; charset=utf-8",
  75. ".svg" => "image/svg+xml",
  76. ".ttl" => "text/turtle; charset=utf-8",
  77. ".txt" => "text/plain; charset=utf-8",
  78. ".xml" => "text/xml; charset=utf-8",
  79. ".xslt" => "text/xml; charset=utf-8",
  80. )
  81. # bandwidth saving:
  82. deflate.mimetypes = (
  83. "application/json",
  84. "application/rdf+xml",
  85. "application/rss+xml",
  86. "application/xslt+xml",
  87. "image/svg+xml",
  88. "text/calendar",
  89. "text/css",
  90. "text/html",
  91. "text/javascript",
  92. "text/plain",
  93. "text/turtle",
  94. # "text/xml",
  95. )
  96. # /usr/share/doc/lighttpd-doc/expire.txt
  97. $HTTP["url"] !~ "/onair\.cgi$" {
  98. # expire all but onair.* - has to set header itself
  99. expire.url = (
  100. "/app/" => "access 0 years",
  101. "" => "access 2 minutes",
  102. )
  103. }
  104. $HTTP["url"] =~ "\.(cfg|js|css|xslt|png|ico|mp3|ttl)$" {
  105. expire.url = ( "" => "access 1 days" )
  106. }
  107. $HTTP["url"] =~ "\.(ics|rdf)$" {
  108. expire.url = ( "" => "access 55 minutes" )
  109. }
  110. $HTTP["url"] =~ "\.(rss)$" {
  111. expire.url = ( "" => "access 2 minutes" )
  112. }
  113. $HTTP["url"] =~ "(modified\.ttl)$" {
  114. expire.url = ( "" => "modification 55 minutes" )
  115. }
  116. $HTTP["url"] =~ "modified-.*\.ttl$" {
  117. expire.url = ( "" => "modification 10 years" )
  118. }
  119. etag.use-inode = "enable"
  120. etag.use-mtime = "enable"
  121. etag.use-size = "enable"
  122. static-file.etags = "enable"