Skip to content

Instantly share code, notes, and snippets.

@thought2
Created January 25, 2020 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thought2/9f99a39a769d9746884e6801eddd0608 to your computer and use it in GitHub Desktop.
Save thought2/9f99a39a769d9746884e6801eddd0608 to your computer and use it in GitHub Desktop.
Location alias nginx nixos
{pkgs, config, ...}:
let
rootDir = pkgs.runCommand "rootdir" {} ''
mkdir $out
echo "foo" > $out/bar
'';
subDir = pkgs.runCommand "subdir" {} ''
mkdir $out
echo "baz" > $out/bar
'';
in
{
networking.firewall.allowedTCPPorts = [ 80 ];
services.nginx.enable = true;
services.nginx.virtualHosts."localhost" = {
addSSL = false;
enableACME = false;
root = rootDir;
locations = {
"~ ^/sub(?:/(.+))?$" = {
alias = subDir + "/$1";
};
};
};
}
$ QEMU_NET_OPTS="hostfwd=tcp::8888-:80" ./result/bin/run-*-vm -display none &
[1] 31210
$ curl localhost:8888/bar
foo
$ curl localhost:8888/sub/bar
<html>
<head><title>500 Internal Server Error</title></head>
<body>
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx</center>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment