Lighty(Lighttpd)虚拟主机配置

时间:2013-04-15 21:25:15

标签: php ruby-on-rails virtualhost lighttpd

我想用PHP设置Lighty,以便在我的开发环境中使用3个不同的域名:

  1. example1.domain.com
  2. example2.domain.com
  3. example4.domain.com
  4. 我已经使用Homebrew安装了PHP 5.4和Lighty,我的目标是在开发过程中使用类似Rails的解决方案来启动/停止Web服务器。基本上,我想:

    $ rails s
    

    表现得像:

    $ lighttpd -D -f lighttpd.conf
    

    我已经运行了服务器,并指向localhost:8000,但由于某些资产以上述域名为前缀,因此某些资产无法正确加载。

    那么就我的问题而言,如何使用上述域名正确配置Lighty虚拟主机?

    这是我目前的Lighty配置:

    server.bind = "0.0.0.0"
    server.port = 8000
    server.document-root = CWD + "/public"
    server.errorlog = CWD + "/lighttpd.error.log"
    accesslog.filename = CWD + "/lighttpd.access.log"
    
    index-file.names = (
      "index.php",
      "index.html",
      "index.htm",
      "default.htm"
    )
    
    server.modules = (
      "mod_fastcgi",
      "mod_accesslog",
      "mod_rewrite"
    )
    
    fastcgi.server = (
      ".php" => ((
        "bin-path" => "/usr/local/bin/php-cgi",
        "socket" => CWD + "/php5.socket"
      ))
    )
    
    mimetype.assign = (
      ".css"        =>  "text/css",
      ".gif"        =>  "image/gif",
      ".htm"        =>  "text/html",
      ".html"       =>  "text/html",
      ".jpeg"       =>  "image/jpeg",
      ".jpg"        =>  "image/jpeg",
      ".js"         =>  "text/javascript",
      ".png"        =>  "image/png",
      ".swf"        =>  "application/x-shockwave-flash",
      ".txt"        =>  "text/plain"
    )
    
    # Making sure file uploads above 64k always work when using IE or Safari
    # For more information, see http://trac.lighttpd.net/trac/ticket/360
    $HTTP["useragent"] =~ "^(.*MSIE.*)|(.*AppleWebKit.*)$" {
      server.max-keep-alive-requests = 0
    }
    
    # Vhost settings
    $HTTP["host"] =~ "example[0-9]+.domain.com" {
      server.document-root = CWD + "/public"
      server.errorlog = CWD + "/lighttpd.error.log"
      accesslog.filename = CWD + "/lighttpd.access.log"
    }
    

2 个答案:

答案 0 :(得分:3)

我有2个想法,您可以使用mod_simple_vhost之类的内容或在主配置中设置根文档目录。

所以,比如:

    $HTTP["host"] =~ "^example([0-9])\.domain\.com$" {
        server.document-root = CWD + "/example%1/"
    }

或使用mod_simple_vhost,这是一个示例配置:

    server.modules += ( "mod_simple_vhost" )

    simple-vhost.server-root   = CWD + "/"
    simple-vhost.document-root = $HTTP["host"] + "/"
    simple-vhost.default-host  = "domain.com"

这会将example1.domain.com的页面放在/CWD/example1.domain.com/。如果这不起作用,请尝试simple-vhost.document-root = CWD + "/" + $HTTP["host"] + "/"

但是,如果您遇到DNS问题,请编辑hosts文件并添加域名,或配置您的名称服务器。

答案 1 :(得分:0)

如果所有虚拟主机都使用与主服务器配置相同的设置,则无需配置任何虚拟主机。您应该只能将域添加到您的hosts文件中,这样它们就会被定向回您的计算机而不是真正的domain.com。在Mac和Linux上的/ etc / hosts或Windows上的C:\ Windows \ System32 \ drivers \ etc \ hosts中添加:

127.0.0.1   example1.domain.com
127.0.0.1   example2.domain.com
127.0.0.1   example3.domain.com