nginx sépartion for static serving
This commit is contained in:
parent
c4426de586
commit
217a273f0b
4 changed files with 65 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
.envrc
|
||||
.direnv
|
||||
/nixos.qcow2
|
||||
|
||||
# Added by cargo
|
||||
|
||||
|
|
62
nix/vm.nix
Normal file
62
nix/vm.nix
Normal file
|
@ -0,0 +1,62 @@
|
|||
{ pkgs, lib, ... }:
|
||||
{
|
||||
nix = {
|
||||
nixPath = [
|
||||
"nixpkgs=${builtins.storePath pkgs.path}"
|
||||
"nixos=${builtins.storePath pkgs.path}"
|
||||
];
|
||||
package = pkgs.lix;
|
||||
};
|
||||
environment.systemPackages = with pkgs; [ wget tmux ];
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
virtualHosts."localhost" = {
|
||||
default = true;
|
||||
locations = {
|
||||
"/" = {
|
||||
root = "/traque/static";
|
||||
tryFiles = "$uri @backend";
|
||||
};
|
||||
"@backend" = {
|
||||
recommendedProxySettings = true;
|
||||
proxyPass = "http://localhost:8000";
|
||||
extraConfig = ''
|
||||
proxy_set_header Connection ''';
|
||||
proxy_http_version 1.1;
|
||||
chunked_transfer_encoding off;
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
'';
|
||||
};
|
||||
};
|
||||
#extraConfig = ''
|
||||
# error_page 502 =503;
|
||||
#'';
|
||||
};
|
||||
};
|
||||
services.getty = {
|
||||
autologinUser = "root";
|
||||
helpLine = lib.mkForce ''
|
||||
On serial console: type Ctrl-a c to switch to the qemu console and `quit` to stop the VM.
|
||||
traque source is on /traque (rw), `cd /traque && ./target/debug/traque` to run the test.
|
||||
Compile from the host for performance (the VM is highly limited).'';
|
||||
};
|
||||
nixos-shell.mounts = {
|
||||
mountHome = false;
|
||||
mountNixProfile = false;
|
||||
cache = "none";
|
||||
extraMounts = {
|
||||
"/traque" = {
|
||||
target = toString ../.;
|
||||
cache = "none";
|
||||
};
|
||||
};
|
||||
};
|
||||
virtualisation = {
|
||||
forwardPorts = [
|
||||
{ from = "host"; host.port = 8000; guest.port = 80; }
|
||||
];
|
||||
};
|
||||
|
||||
system.stateVersion = "24.11";
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs ? (import <nixpkgs>) { }, lib ? pkgs.lib}:
|
||||
pkgs.mkShell {
|
||||
buildInputs = with pkgs; [ cargo rustc rustfmt ];
|
||||
buildInputs = with pkgs; [ cargo rustc rustfmt nixos-shell ];
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#[macro_use]
|
||||
extern crate rocket;
|
||||
use rocket::{
|
||||
fs::{relative, FileServer},
|
||||
response::stream::Event,
|
||||
tokio::{
|
||||
self, select,
|
||||
|
@ -102,8 +101,7 @@ async fn rocket() -> _ {
|
|||
.manage(key)
|
||||
.mount("/", routes![index])
|
||||
.mount("/track", track::routes())
|
||||
.mount("/admin", admin::routes())
|
||||
.mount("/", FileServer::from(relative!("static")));
|
||||
.mount("/admin", admin::routes());
|
||||
tokio::spawn(async move {
|
||||
let mut clean_interval = time::interval(5 * EVENT_TIMEOUT);
|
||||
let mut coord_interval = time::interval(Duration::from_millis(3000));
|
||||
|
|
Loading…
Reference in a new issue