Created
January 25, 2020 18:30
-
-
Save thought2/9f99a39a769d9746884e6801eddd0608 to your computer and use it in GitHub Desktop.
Location alias nginx nixos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{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"; | |
}; | |
}; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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