--- title: Install a web server (nginx) params: target: { type: choice, options: [lxc, existing], default: lxc, label: Install on } server_name: { type: name, required: true, default: web, label: Server name } host: { type: host, required: true, default: "{{ct.host}}", label: Target server } --- # Install nginx on {{host}} Example of a chained notebook. Choose **Install on: lxc** to create a fresh Proxmox container first (its form appears below), or **existing** to pick a server from Hosts. The install steps then target **Target server**, which defaults to the new container once it is in Hosts. :::when{target=lxc} ## New container ::use{notebook="infra/lxc-container.md" as=ct with="hostname={{server_name}}"} ::: ## Install Runs as root, or through passwordless `sudo -n` for other users. ```sh {check host="{{host}}" id=apt title="Debian/Ubuntu with apt and systemd"} command -v apt-get command -v systemctl ``` ```sh {check host="{{host}}" id=installed title="nginx is installed"} dpkg-query -W -f='${Status}\n' nginx | grep -qx 'install ok installed' ``` ```sh {run host="{{host}}" id=install title="Install and start nginx" confirm timeout=600} if [ "$(id -u)" -eq 0 ]; then as_root=""; else as_root="sudo -n"; fi $as_root apt-get update $as_root env DEBIAN_FRONTEND=noninteractive apt-get install -y nginx $as_root systemctl enable --now nginx ``` ```sh {check host="{{host}}" id=active title="nginx is running and answers"} systemctl is-active nginx timeout 5 bash -c 'exec 3<>/dev/tcp/127.0.0.1/80' ``` :::after{step=install} nginx is installed on **{{host}}**. Put your site into `/etc/nginx/sites-available/` and review the firewall before exposing it. :::