Debian Server from Scratch
A quick guide on setting up a minimal but secure HTTPS web server on a Debian (12) Linux server.
Initial setup
Setup SSH, auth, and firewall.
- Login as root to your host machine.
- Setup an SSH key.
- Create a non-root user:
adduser <username>and fill in the details - Allow your new user to use
sudo:usermod -aG sudo <username> - Add your ssh key to the new user's authorized keys file:
/home/<username>/.ssh/authorized_keys(you will need to make the folder first withmkdir /home/<username>/.ssh). - Make sure your new user owns it:
chown -R <username>:<username> /home/<username>/.ssh - Setup a firewall
apt updateapt install ufwufw allow OpenSSHufw enableufw status
- Add the following to
/etc/ssh/sshd_config(if it's not already there) to disable root password login (use SSH keys to login):PermitRootLogin prohibit-password
PasswordAuthentication no - Logout and use your non-root user for everything else (
<username>).
Nginx
-
sudo apt update -
sudo apt install nginx -
sudo ufw allow 'Nginx HTTP' -
sudo ufw allow 'Nginx HTTPS' -
Create a server block
-
sudo nano /etc/nginx/sites-available/<site-name> -
Paste in the following (make sure to replace
<domain>with your actual domain):server {
listen 80;
listen [::]:80;
server_name <domain>;
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:3000;
}
}
-
-
Enable the server block:
sudo ln -s /etc/nginx/sites-available/<site-name> /etc/nginx/sites-enabled/<site-name> -
Disable the default server block:
sudo rm /etc/nginx/sites-enabled/default -
Verify that your config is valid:
sudo nginx -t
Setup Certbot (Let's Encrypt)
sudo apt install certbot python3-certbot-nginxsudo certbot --nginx -d <domain>- Test auto renewal with:
sudo certbot renew --dry-run
Install Node.js
- Install nvm: https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script
- As of writing this, the command is:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
- As of writing this, the command is:
- If you don't want to restart your shell, source you bashrc:
source ~/.bashrc - Install Node.js:
nvm install --lts - Install a specific npm version:
npm i -g npm@<version>
Test the server
npm i -g @electrovir/basic-serverbasic-server 3000