www.conf 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #
  2. # 提供 www 目录的静态资源服务
  3. #
  4. include mime.types;
  5. sendfile on;
  6. charset utf-8;
  7. # 安装步骤多,节省的流量不多,暂时不开
  8. # brotli_static on;
  9. # gzip_static on;
  10. gzip on;
  11. log_not_found off;
  12. error_page 404 = /404.html;
  13. location = /404.html {
  14. internal;
  15. root ../www;
  16. # http 重定向到 https(忽略 localhost 或 IP 访问)
  17. access_by_lua_block {
  18. if ngx.var.scheme == 'https' then
  19. return
  20. end
  21. local host = ngx.var.host
  22. if host == 'localhost' then
  23. return
  24. end
  25. if ngx.re.match(host, [[^\d+\.\d+\.\d+\.\d+$]]) then
  26. return
  27. end
  28. local url = host .. ':8443' .. ngx.var.request_uri
  29. ngx.redirect('https://' .. url, 301)
  30. }
  31. # 永久重定向申请: https://hstspreload.org/
  32. more_set_headers
  33. 'strict-transport-security: max-age=99999999; includeSubDomains; preload'
  34. ;
  35. }
  36. location / {
  37. access_log logs/access.log log_www buffer=64k flush=1s;
  38. root ../www;
  39. index 404.html;
  40. }
  41. # HTTPS 证书申请验证
  42. location /.well-known/acme-challenge/ {
  43. access_log logs/acme.log combined;
  44. root ../acme;
  45. }