我有一台运行lighttp的服务器。出于测试目的,如果请求源自特定IP,我想使用不同的主机。例如:
$HTTP["host"] =~ "(^|\.)example\.com$" {
#### for live system
server.document-root = "/var/www/example.com/http"
#### for requests from ip xxx
server.document-root = "/var/www/example.com/testing/http"
…
}
使用配置修改是否可以实现?
答案 0 :(得分:2)
使用$HTTP["remoteip"]
进行此项检查:
远程IP或远程网络上的
$HTTP["remoteip"]
匹配(警告:无法启用IPv6)
然后你的配置文件:
$HTTP["host"] =~ "(^|\.)example\.com$" {
#### for live system
$HTTP["remoteip"] == "10.10.10.10" {
server.document-root = "/var/www/example.com/http"
}
#### for requests from ip xxx
$HTTP["remoteip"] == "11.11.11.11" {
server.document-root = "/var/www/example.com/testing/http"
}
}
您还可以使用else
:
$HTTP["host"] =~ "(^|\.)example\.com$" {
#### for requests from ip xxx
$HTTP["remoteip"] == "11.11.11.11" {
server.document-root = "/var/www/example.com/testing/http"
}
#### for live system
else {
server.document-root = "/var/www/example.com/http"
}
}