diff --git a/appmgr/src/bin/embassyd.rs b/appmgr/src/bin/embassyd.rs index 14c984049..679a4ac12 100644 --- a/appmgr/src/bin/embassyd.rs +++ b/appmgr/src/bin/embassyd.rs @@ -3,6 +3,7 @@ use std::time::Duration; use color_eyre::eyre::eyre; use embassy::context::{DiagnosticContext, RpcContext}; use embassy::db::subscribe; +use embassy::hostname::get_hostname; use embassy::middleware::auth::auth; use embassy::middleware::cors::cors; use embassy::middleware::diagnostic::diagnostic; @@ -66,10 +67,17 @@ async fn inner_main(cfg_path: Option<&str>) -> Result, Error> { .expect("send shutdown signal"); }); - tokio::fs::write( - "/etc/nginx/sites-available/default", - include_str!("../nginx/main-ui.conf"), - ) + tokio::fs::write("/etc/nginx/sites-available/default", { + let info = embassy::db::DatabaseModel::new() + .server_info() + .get(&mut rpc_ctx.db.handle(), true) + .await?; + format!( + include_str!("../nginx/main-ui.conf.template"), + lan_hostname = info.lan_address.host_str().unwrap(), + tor_hostname = info.tor_address.host_str().unwrap() + ) + }) .await .with_ctx(|_| { ( diff --git a/appmgr/src/nginx/main-ui.conf b/appmgr/src/nginx/main-ui.conf deleted file mode 100644 index 27c2e5ecd..000000000 --- a/appmgr/src/nginx/main-ui.conf +++ /dev/null @@ -1,42 +0,0 @@ -server { - listen 443 ssl default_server; - listen [::]:443 ssl default_server; - ssl_certificate /etc/nginx/ssl/embassy_main.cert.pem; - ssl_certificate_key /etc/nginx/ssl/embassy_main.key.pem; - - root /var/www/html/main; - - index index.html index.htm index.nginx-debian.html; - - server_name _; - - proxy_buffering off; - proxy_request_buffering off; - proxy_socket_keepalive on; - proxy_http_version 1.1; - proxy_read_timeout 1800; - - location /rpc/ { - proxy_pass http://127.0.0.1:5959/; - } - - location /ws/ { - proxy_pass http://127.0.0.1:5960/; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - } - - location /marketplace/ { - proxy_pass https://beta-registry-0-3.start9labs.com/; # TODO - } - - location / { - try_files $uri $uri/ =404; - } -} -server { - listen 80 default_server; - listen [::]:80 default_server; - server_name _; - return 301 https://$host$request_uri; -} \ No newline at end of file diff --git a/appmgr/src/nginx/main-ui.conf.template b/appmgr/src/nginx/main-ui.conf.template new file mode 100644 index 000000000..71c9e2ed1 --- /dev/null +++ b/appmgr/src/nginx/main-ui.conf.template @@ -0,0 +1,84 @@ +server {{ + listen 443 ssl default_server; + listen [::]:443 ssl default_server; + ssl_certificate /etc/nginx/ssl/embassy_main.cert.pem; + ssl_certificate_key /etc/nginx/ssl/embassy_main.key.pem; + + root /var/www/html/main; + + index index.html index.htm index.nginx-debian.html; + + server_name {lan_hostname}; + + proxy_buffering off; + proxy_request_buffering off; + proxy_socket_keepalive on; + proxy_http_version 1.1; + proxy_read_timeout 1800; + + location /rpc/ {{ + proxy_pass http://127.0.0.1:5959/; + }} + + location /ws/ {{ + proxy_pass http://127.0.0.1:5960/; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + }} + + location /marketplace/ {{ + proxy_pass https://beta-registry-0-3.start9labs.com/; # TODO + }} + + location / {{ + try_files $uri $uri/ =404; + }} +}} +server {{ + listen 80; + listen [::]:80; + server_name {lan_hostname}; + return 301 https://$host$request_uri; +}} +server {{ + listen 80 default_server; + listen [::]:80 default_server; + ssl_certificate /etc/nginx/ssl/embassy_main.cert.pem; + ssl_certificate_key /etc/nginx/ssl/embassy_main.key.pem; + + root /var/www/html/main; + + index index.html index.htm index.nginx-debian.html; + + server_name {tor_hostname}; + + proxy_buffering off; + proxy_request_buffering off; + proxy_socket_keepalive on; + proxy_http_version 1.1; + proxy_read_timeout 1800; + + location /rpc/ {{ + proxy_pass http://127.0.0.1:5959/; + }} + + location /ws/ {{ + proxy_pass http://127.0.0.1:5960/; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + }} + + location /marketplace/ {{ + proxy_pass https://beta-registry-0-3.start9labs.com/; # TODO + }} + + location / {{ + try_files $uri $uri/ =404; + }} +}} +server {{ + listen 443 ssl; + listen [::]:443; + server_name {tor_hostname}; + return 301 http://$host$request_uri; +}} \ No newline at end of file