我需要帮助在 lighttpd 中设置虚拟主机。我在/var/www/lighttpd
目录中有 lighttpd 默认网页,并且我为其他网站创建了其他目录/var/www/web1.com/public_html
,/var/www/web2.com/public_html
我尝试按照 lighttpd 网站上的文档页面和其他在线指南操作,但没有成功。我只想知道我应该编辑什么文件以及添加什么才能为其他虚拟主机/目录的网站提供服务?
完整配置太长,但这是我添加到默认 lighttpd.conf 中的内容
$HTTP["host"] =~ "^www\.(.*)$" {
url.redirect-code = 301
url.redirect = (
"/(.*)" => "http://%1/$1"
)
}
$HTTP["host"] == "www.web1.com" {
#url.redirect = (
# "^/(.*)" => "http://web1.com/$1",
# )
server.document-root = "/var/www/web1.com/public_html"
# accesslog.filename = "/var/www/web1.com/logs/error.log"
}
$HTTP["host"] == "web2.com" {
server.document-root = "/var/www/web2.com/public_html"
# accesslog.filename = "/var/www/web2.com/logs/error.log"
}
$HTTP["host"] == "web3.com" {
server.document-root = "/var/www/web3.com/public_html"
# accesslog.filename = "/var/www/web3.com/logs/error.log"
}
答案1
您将需要进行如下配置:
$HTTP["host"] == "web1.com" {
server.document-root = "/var/www/web1.com/public_html"
}
$HTTP["host"] == "web2.com" {
server.document-root = "/var/www/web2.com/public_html"
}
这应该是将这两个目录映射到这两个主机头所需的全部操作。如果这不起作用,您能否更详细地说明在尝试使用此配置时遇到的问题类型?
编辑:
要将www
域名重定向到非 www,请使用如下配置:
$HTTP["host"] =~ "^www\.(.*)$" {
url.redirect-code = 301
url.redirect = (
"/(.*)" => "http://%1/$1"
)
}
答案2
加载优质 laravel、slim 和 codeigniter
uncomment: "mod_rewrite",
uncomment: "mod_simple_vhost",
var.basedir = "/var/www/localhost"
server.document-root = var.basedir + "/htdocs"
接下来的三行创造了奇迹!
simple-vhost.server-root = "/var/www/localhost/htdocs/vhost"
simple-vhost.default-host = "myhost1.com"
simple-vhost.document-root = "/public"
配置重写
url.rewrite-if-not-file = ("(.*)" => "/index.php/$0")
为每个主机创建一个文件夹,例如:
myhost1.com /var/www/localhost/htdocs/vhost/myhost1.com
otherhost.com /var/www/localhost/htdocs/vhost/otherhost.com
将您的主机添加到 /etc/hosts 文件
127.0.0.1 myhost1.com
127.0.0.1 otherhost.com
重新加载 lighttpd
rc-service -vv lighttpd restart