99-lighttpd-shaarligo.conf 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ### ShaarliGo begin
  2. var.shaarli_go_path_0 = "/<url path to, but excluding shaarligo.cgi>/" # change as needed, keep leading and trailing slash
  3. # Setup
  4. #
  5. # 1. edit above var.shaarli_go_path_0 = ...,
  6. # 2. put this file into /etc/lighttpd/conf-available/
  7. # 3. $ sudo /usr/sbin/lighty-enable-mod lighttpd-shaarligo
  8. # 4. $ sudo service lighttpd force-reload
  9. # 5. drop shaarligo.cgi in filesystem location matching shaarli_go_path_0
  10. # 6. point browser to http://example.com/.../shaarligo.cgi
  11. # In case you have simple_vhost enabled, put this config into server.conf
  12. # inside your vhost directory.
  13. #
  14. # https://redmine.lighttpd.net/projects/1/wiki/TutorialConfiguration
  15. # https://redmine.lighttpd.net/projects/1/wiki/docs_modsimplevhost
  16. server.modules += ("mod_setenv")
  17. # below is a workaround, if 'config_servers' can't be patched:
  18. # $ sudo fgrep server.breakagelog /etc/lighttpd/config_servers
  19. # echo " server.breakagelog = \"$base/$VHOST/logs/error.log\""
  20. # server.breakagelog = "/var/www/lighttpd/.../logs/error.log"
  21. $HTTP["url"] =~ "^"+shaarli_go_path_0 {
  22. cgi.assign = ( "shaarligo.cgi" => "" ) # execute without interpreter
  23. server.error-handler-404 = shaarli_go_path_0 + "themes/current/404.html"
  24. url.redirect = (
  25. # start with ? to make the trailing slash of "^"+shaarli_go_path_0 optional:
  26. "^"+shaarli_go_path_0 + "?\?(..*)$" => "shaarligo.cgi?$1", # probe & shaarli
  27. "^"+shaarli_go_path_0 + "shaarligo.cgi\?do=(rss|atom)$" => "../o/p/", # I AM the feed
  28. )
  29. index-file.names = ( "index.html", "index.xml" )
  30. setenv.add-response-header += (
  31. # nice
  32. "X-Powered-By" => "http://purl.mro.name/ShaarliGo",
  33. # recommended
  34. # http://www.golem.de/news/content-security-policy-schutz-vor-cross-site-scripting-1306-99795.html
  35. # http://www.w3.org/TR/CSP/#example-policies
  36. "Content-Security-Policy" => "base-uri 'none'; form-action 'self'; frame-ancestors 'none'; default-src 'none'; style-src 'self' 'unsafe-inline'; script-src 'self' 'sha256-hGqewLn4csF93PEX/0TCk2jdnAytXBZFxFBzKt7wcgo='; connect-src 'self'; font-src 'self'; img-src data: 'self'; media-src 'none';",
  37. "Referrer-Policy" => "no-referrer",
  38. "X-Frame-Options" => "DENY",
  39. "X-Content-Type-Options" => "nosniff",
  40. "Strict-Transport-Security" => "max-age=15768000",
  41. # "Access-Control-Allow-Origin" => "*",
  42. # check results https://observatory.mozilla.org/analyze/l.mro.name
  43. )
  44. mimetype.assign = (
  45. ".css" => "text/css; charset=utf-8",
  46. ".html" => "text/html; charset=utf-8",
  47. ".js" => "text/javascript; charset=utf-8",
  48. ".json" => "application/json",
  49. ".png" => "image/png",
  50. ".svg" => "image/svg+xml",
  51. ".txt" => "text/plain; charset=utf-8",
  52. ".xml" => "text/xml; charset=utf-8",
  53. ".xslt" => "text/xsl; charset=utf-8", # a Chromism. https://stackoverflow.com/a/21604288
  54. ".woff" => "application/font-woff",
  55. ".woff2" => "application/font-woff",
  56. )
  57. compress.filetype = (
  58. "application/atom+xml; charset=utf-8",
  59. "application/json",
  60. "application/xslt+xml; charset=utf-8",
  61. "image/svg+xml",
  62. "text/css; charset=utf-8",
  63. "text/html; charset=utf-8",
  64. "text/javascript; charset=utf-8",
  65. "text/plain; charset=utf-8",
  66. "text/xml; charset=utf-8",
  67. "text/xsl; charset=utf-8",
  68. )
  69. $HTTP["url"] =~ "^"+shaarli_go_path_0+"themes/" { setenv.add-response-header += ( "Cache-Control" => "max-age=604800, public" ) } # 7 days
  70. $HTTP["url"] !~ "^"+shaarli_go_path_0+"themes/" { setenv.add-response-header += ( "Cache-Control" => "no-cache" ) }
  71. }
  72. $HTTP["url"] =~ "^"+shaarli_go_path_0 + "app/" { url.access-deny = ("") }
  73. #### ShaarliGo end
  74. $HTTP["url"] !~ "^/\.well-known/" {
  75. # handle http -> https redirects
  76. $HTTP["scheme"] == "http" {
  77. # capture vhost name with regex conditiona -> %0 in redirect pattern
  78. # must be the most inner block to the redirect rule
  79. # $HTTP["host"] =~ ".*" { url.redirect = (".*" => "https://%0$0") }
  80. }
  81. }