2025-03-29 23:50:31 +01:00
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
name = "nginx-globalredirect";
|
2022-12-03 18:58:33 +01:00
|
|
|
|
2025-03-29 23:50:31 +01:00
|
|
|
nodes = {
|
|
|
|
webserver =
|
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
{
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts.localhost = {
|
|
|
|
globalRedirect = "other.example.com";
|
|
|
|
# Add an exception
|
|
|
|
locations."/noredirect".return = "200 'foo'";
|
2024-12-10 20:26:33 +01:00
|
|
|
};
|
2022-12-03 18:58:33 +01:00
|
|
|
};
|
2025-03-29 23:50:31 +01:00
|
|
|
};
|
|
|
|
};
|
2022-12-03 18:58:33 +01:00
|
|
|
|
2025-03-29 23:50:31 +01:00
|
|
|
testScript = ''
|
|
|
|
webserver.wait_for_unit("nginx")
|
|
|
|
webserver.wait_for_open_port(80)
|
2022-12-03 18:58:33 +01:00
|
|
|
|
2025-03-29 23:50:31 +01:00
|
|
|
webserver.succeed("curl --fail -si http://localhost/alf | grep '^Location:.*/alf'")
|
|
|
|
webserver.fail("curl --fail -si http://localhost/noredirect | grep '^Location:'")
|
|
|
|
'';
|
|
|
|
}
|