nixpkgs-suyu/nixos/tests/nginx-globalredirect.nix
Vincent Bernat fc39b5ecc8 nginx: make global redirect vhost option accept exceptions
By moving the return into a location directive, one can provide
exceptions by adding locations. This is similar to what the forceSSL
option does.
2022-12-18 12:21:27 +01:00

24 lines
657 B
Nix

import ./make-test-python.nix ({ pkgs, ... }: {
name = "nginx-globalredirect";
nodes = {
webserver = { pkgs, lib, ... }: {
services.nginx = {
enable = true;
virtualHosts.localhost = {
globalRedirect = "other.example.com";
# Add an exception
locations."/noredirect".return = "200 'foo'";
};
};
};
};
testScript = ''
webserver.wait_for_unit("nginx")
webserver.wait_for_open_port(80)
webserver.succeed("curl --fail -si http://localhost/alf | grep '^Location:.*/alf'")
webserver.fail("curl --fail -si http://localhost/noredirect | grep '^Location:'")
'';
})