如何引导访问者根据他们的`主机`某些HTTP服务?

我想用nginxconfiguration来指导用户不同的Web服务。

这个场景是主机名从192.168.1.1192.168.1.255的内部用户。我想为他们提供一些web服务,但是对于其他的外部访问者我不希望这样做。

我知道我可以使用IP_TABLES来启用这个function,但是我使用IP_TABLE规则主要是为了防火墙的目的,我不想把它和这个configuration混合在一起。

nginx.conf有没有可用的configuration?

您可以将GEO模块与map指令一起使用:

 http { geo $special_service { default 0; 192.168.1.0/24 1; } server { if ($special_service) { return 302 $scheme://$server_name/special-service/; } } } 

创build一个覆盖敏感内容的单独location块。

请记住,configuration指令不会inheritance; 您需要在新块中包含现有“您的内容所需位置”中的任何内容。

 location /path/to/sensitive/stuff { # any other config that you need goes here.. # ... allow 192.168.1.0/24; deny all; }