• lighttpd虚拟主机配置
    时间:2008-12-30   作者:佚名   出处:互联网

    lighttpd.conf解释

       1. server.use-ipv6 = "disable" # 缺省为禁用
       2. server.event-handler = "linux-sysepoll" # Linux环境下epoll系统调用可提高吞吐量
       3. #server.max-worker = 10 # 如果你的系统资源没跑满,可考虑调高 lighttpd进程数
       4. server.max-fds = 4096 # 默认的,应该够用了,可根据实际情况调整
       5. server.max-connections = 4096 # 默认等于 server.max-fds
       6. server.network-backend = "linux-sendfile"
       7. server.max-keep-alive-requests = 0 # 在一个keep-alive会话终止连接前能接受处理的最大请求数。0为禁止
       8.
       9. # 设置要加载的module
      10. server.modules = (
      11.    "mod_rewrite",
      12.    "mod_redirect",
      13. # "mod_alias",
      14.    "mod_access",
      15. # "mod_cml",
      16. # "mod_trigger_b4_dl",
      17.    "mod_auth",
      18.    "mod_expire",
      19. # "mod_status",
      20. # "mod_setenv",
      21.    "mod_proxy_core",
      22.    "mod_proxy_backend_http",
      23.    "mod_proxy_backend_fastcgi",
      24. # "mod_proxy_backend_scgi",
      25. # "mod_proxy_backend_ajp13",
      26. # "mod_simple_vhost",
      27.    "mod_evhost",
      28. # "mod_userdir",
      29. # "mod_cgi",
      30.    "mod_compress",
      31. # "mod_ssi",
      32. # "mod_usertrack",
      33. # "mod_secdownload",
      34. # "mod_rrdtool",
      35.    "mod_accesslog" )
      36.
      37. # 网站根目录
      38. server.document-root = "/var/www/"
      39.
      40. # 错误日志位置
      41. server.errorlog = "/var/log/lighttpd/error.log"
      42.
      43. # 网站Index
      44. index-file.names = ( "index.php", "index.html",
      45.    "index.htm", "default.htm" )
      46.
      47. # 访问日志, 以及日志格式 (combined), 使用X-Forwarded-For可越过代理读取真实ip
      48. accesslog.filename = "/var/log/lighttpd/access.log"
      49. accesslog.format = "%{X-Forwarded-For}i %v %u %t \"%r\" %s %b \"%{User-Agent}i\" \"%{Referer}i\""
      50.
      51. # 设置禁止访问的文件扩展名
      52. url.access-deny = ( "~", ".inc", ".tpl" )
      53.
      54. # 服务监听端口
      55. server.port = 80
      56.
      57. # 进程id记录位置
      58. server.pid-file = "/var/run/lighttpd.pid"
      59.
      60. # virtual directory listings 如果没有找到index文件就列出目录。建议disable。
      61. dir-listing.activate = "disable"
      62.
      63. # 服务运行使用的用户及用户组
      64. server.username = "www"
      65. server.groupname = "www"
      66.
      67. # gzip压缩存放的目录以及需要压缩的文件类型
      68. compress.cache-dir = "/tmp/lighttpd/cache/compress/"
      69. compress.filetype = ("text/plain", "text/html")
      70.
      71. # fastcgi module
      72. # for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini
      73. $HTTP["url"] =~ "\.php$" {
      74.    proxy-core.balancer = "round-robin"
      75.    proxy-core.allow-x-sendfile = "enable"
      76. # proxy-core.check-local = "enable"
      77.    proxy-core.protocol = "fastcgi"
      78.    proxy-core.backends = ( "unix:/tmp/php-fastcgi1.sock","unix:/tmp/php-fastcgi2.sock" )
      79.    proxy-core.max-pool-size = 16
      80. }
      81.
      82. # 权限控制
      83. auth.backend = "htpasswd"
      84. auth.backend.htpasswd.userfile = "/var/www/htpasswd.userfile"
      85.
      86. # 基于 evhost 的虚拟主机 针对域名
      87. $HTTP["host"] == "a.lostk.com" {
      88.    server.document-root = "/var/www/lostk/"
      89.    server.errorlog = "/var/log/lighttpd/lostk-error.log"
      90.    accesslog.filename = "/var/log/lighttpd/lostk-access.log"
      91.
      92.    # 设定文件过期时间
      93.    expire.url = (
      94.    "/css/" => "access 2 hours",
      95.    "/js/" => "access 2 hours",
      96.    )
      97.
      98.    # url 跳转
      99.    url.redirect = (
     100.    "^/$" => "/xxx/index.html",
     101.    )
     102.
     103.    # url 重写 (cakephp可用)
     104.    url.rewrite = (
     105.    "^/(css|js)/(.*)$" => "/$1/$2",
     106.    "^/([^.]+)$" => "/index.php?url=$1",
     107.    )
     108.
     109.    # 权限控制
     110.    auth.require = ( "" =>
     111.    (
     112.    "method" => "basic",
     113.    "realm" => "admin only",
     114.    "require" => "user=admin1|user=admin2" # 允许的用户, 用户列表文件 在上面配置的auth.backend.htpasswd.userfile 里
     115.    ),
     116.    )
     117. }
     118.
     119. # 针对端口的虚拟主机
     120. $SERVER["socket"] == "192.168.0.1:8000" {
     121.    server.document-root = "/var/www/xxx/"
     122.    server.errorlog = "/var/log/lighttpd/test-error.log"
     123.    accesslog.filename = "/var/log/lighttpd/test-access.log"
     124.
     125.    # ...
     126. }

    附加:正则配置站点

    $HTTP["host"] =~ "(^|\.)debian\.com" {
    server.name = "(^|\.)debian\.com"
    server.document-root = "/www/debian.com/"
    server.errorlog = "/var/www/error.log"
    accesslog.filename = "/var/www/access.log"
    }

    $HTTP["host"] == "bbs.aaa.com" {
    server.name = "bbs.aaa.com"
    server.document-root = "/var/www/bbs"
    server.errorlog = "/var/www/bbs/error.log"
    accesslog.filename = "/var/www/bbs/access.log"
    }

    网友留言/评论

    我要留言/评论