lighttpd 多域名

lighttpd 虚拟主机配置

编辑 /etc/lightpd/lighttpd.conf 文件,添加:

$HTTP
[
"host"
]
== “wiki.guoshuang
.com
{

 
server.name
= “wiki.guoshuang
.com
”   server.document
-
root = “/
var/
www/
guoshuang”
 
server.errorlog
= “/
var/
www/
guoshuang/
cuowu.log

 
accesslog.filename
= “/
var/
www/
guoshuang/
cuowu.log

 
}

server.name
= “wiki.guoshuang
.com

 
server.document
-
root = “/
var/
www/
guoshuang”
 
server.errorlog
= “/
var/
www/
guoshuang/
cuowu.log

 
accesslog.filename
= “/
var/
www/
guoshuang/
cuowu.log

 
}

 
 
 
保存。重启 lightpd 即可。
 
lighttpd(别名)虚拟目录配置
 
server.modules
+
= (
“mod_alias” )

 
alias
.url
= (
/
cgi-
bin/
” =&
gt; “/
home/
lighttpd/
theos.in
/
cgi-
bin/
)

 
Browse all documents installed at /
usr/
share/
doc/
directory with following alias
:
 
alias
.url
= (
/
docs/
” =&
gt; “/
usr/
share/
doc/
)

 
alias
.url
+
= (
/
stats/
” =&
gt; “/
home/
theos.in
/
http/
webalizer/
)

alias
.url
= (
/
cgi-
bin/
” =&
gt; “/
home/
lighttpd/
theos.in
/
cgi-
bin/
)

 
Browse all documents installed at /
usr/
share/
doc/
directory with following alias
:
 
alias
.url
= (
/
docs/
” =&
gt; “/
usr/
share/
doc/
)

 
alias
.url
+
= (
/
stats/
” =&
gt; “/
home/
theos.in
/
http/
webalizer/
)

 
 
 
拒绝下载 ~ 和 .inc
文件。
 
url.access
-
deny = (
“~”, “.inc
)

 
wikipedia 虚拟主机以后需要修改 LocalSettings.php
的目录。否则报告 404
错误。
 
--------------------------------------------------------------------------------------------------

Description¶
Simple assumption:
 
Every virtual host is in
a directory below a base directory in
a path that is the same as the name of the vhost. Below
this vhost path might be an extra directory which is the document root of the vhost.
 
The
document root for
each vhost is built from three values:
 
-
server-
root
-
hostname
-
document-
root
 
The complete document root is constructed either by
 
server-
root +
hostname +
document-
root
or
if
this path does not
exist by
 
server-
root +
default-
host +
document-
root
A small example should make this idea clear:
 
/
var/
www/

/
var/
www/
logs/

/
var/
www/
servers/

/
var/
www/
servers/
example.org
/

/
var/
www/
servers/
example.org
/
lib/

/
var/
www/
servers/
example.org
/
pages/

/
var/
www/
servers/
mail.example
.org
/

/
var/
www/
servers/
mail.example
.org
/
lib/

/
var/
www/
servers/
mail.example
.org
/
pages/

 
simple-
vhost.server
-
root = "/var/www/servers/"

simple-
vhost.default
-
host = "example.org"

simple-
vhost.document
-
root = "pages"

With this setup, requests for
"example.org"
or
"something-else.example.org"
will go to /
var/
www/
server/
example.org
/
pages, while
requests for
"mail.example.org"
will go to /
var/
www/
server/
mail.example
.org
/
pages. You
can use symbolic links to map several hostnames to the same directory.
 
Conditionals
vs. simple
-
vhost¶
You have to keep in
mind that conditionals and
simple-
vhost interfere with one another.
 
simple
-
vhost.server
-
root = "/var/www/servers/"

simple-
vhost.default
-
host = "example.org"

simple-
vhost.document
-
root = "pages"

 
$HTTP
[
"host"
]
== "news.example.org"
{

    server.document
-
root = "/var/www/servers/news2.example.org/pages/"

}

When
news.example
.org
is requested, the server.document
-
root will be set to /
var/
www/
servers/
news2.example
.org
/
pages/
, but simple-
vhost will overwrite it shortly afterwards.
 
If
/
var/
www/
servers/
news.example
.org
/
pages/
exists, that will be used. If
not
, /
var/
www/
servers/
example.org
/
pages/
will be taken because it is the default.
 
To
use conditionals together with simple-
vhost, you should do
this:
 
$HTTP
[
"host"
]
!= "news.example.org"
{

    simple-
vhost.server
-
root = "/var/www/servers/"

    simple-
vhost.default
-
host = "example.org"

    simple-
vhost.document
-
root = "pages"

}

 
$HTTP
[
"host"
]
== "news.example.org"
{

    server.document
-
root = "/var/www/servers/news2.example.org/pages/"

}

It will enable simple vhosting for
all hosts other than news.example
.org
.
 
For
two or
more hosts:
 
$HTTP
[
"host"
]
!~ "^(test1\.
example\.
org|test2\.
example\.
org)$"

{

    simple-
vhost.server
-
root         = "/var/www"

    simple-
vhost.document
-
root       = "/html/"

    ## the default host if no host is sent

    simple-
vhost.default
-
host        = "example.org"

}

 
$HTTP
[
"host"
]
== "test1.example.org"
{

    server.document
-
root = "/home/user/sites/test1.example.org/"

    accesslog.filename
= "/home/user/sites/logs/test1.example.org.access.log"

}

 
$HTTP
[
"host"
]
== "test2.example.org"
{

    server.document
-
root = "/home/user/sites/test2.example.org"

    accesslog.filename
= "/home/user/sites/logs/test2.example.org.access.log"

}

It will enable simple virtual hosting for
all hosts other than test1.example
.org
and
test2.example
.org
.
 
Of
course you will need to setup permissions for
folders (
change owner to the user running lighttpd)
if
you do
it like in
that example.
 
Options

simple-
vhost.server
-
root¶
The root of the virtual host
 
simple-
vhost.default
-
host¶
Use this hostname if
the requested hostname does not
have its own directory
 
simple-
vhost.document
-
root¶
The path below the vhost directory
 
Tips¶
Make sure mod_simple_vhost is the first mod in
'server.modules'
list,when
you are using mod_simple_vhost with mod_cache and
mod_proxy.
 
You
can configure a virtual host with multiple domain names by using 'or'
syntax such as:
 
$HTTP
[
"host"
]
=~ "^(hosta\.
example\.
org|hostb\.
example\.
net)$"

{

    ... virtualhost
configuration here ...
}

WWW¶
You do
not
need to use two entries for
example.com
and
<
a href="http://www.example.com/"
>
www.example
.com
</
a>
. The
following syntax will act as a catch
all for
both example.com
and
any subdomains under it:
 
$HTTP
[
"host"
]
=~ "(^|\.
)example\.
com$"

{

    ...
}

此条目发表在article分类目录,贴了标签。将固定链接加入收藏夹。