0

我有一台运行 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"
    …
}

这可以通过使用配置修改来实现吗?

4

1 回答 1

2

用于$HTTP["remoteip"]此检查:

$HTTP["remoteip"]在远程 IP 或远程网络上匹配(警告:不适用于启用 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"
    }
}
于 2012-08-10T10:08:13.547 回答